I have this iframe:
<iframe id="myiframe" src="..." style="width: 90px; height: 70px">
</iframe>
How can I change the width ? Ive tried with:
$("#myiframe").attr("width", 104);
But the iframe is showing with a width of 90px.
How can I change t开发者_StackOverflowhat 90px ? Thanks!!!
$("#myiframe").css({"width": 104});
Use the $.width()
method:
$("#myiframe").width(104);
Note that this method is both a getter, and a setter. Passing it a value will declare a width for the matched element, and passing no value will return the current width of the matched element.
alert( $("#myiframe").width() ); // 104
Online Demo: http://jsbin.com/egozax/edit
What's wrong with changing the value inline?
<iframe id="myiframe" src="..." style="width: 104px; height: 70px">
</iframe>
However, your jQuery code has a flaw: it's adding a width
property to the iframe, it's not changing its style
.
try
$("#myiframe").attr("width", "104px");
精彩评论