Reputation: 177
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 that 90px ? Thanks!!!
Upvotes: 1
Views: 6813
Reputation: 268326
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
Upvotes: 1
Reputation: 11085
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
.
Upvotes: 0