开发者

How to change iFrame style

开发者 https://www.devze.com 2023-03-15 19:31 出处:网络
I have this iframe: <iframe id=\"myiframe\" src=\"...\" style=\"width: 90px; height: 70px\"> </iframe>

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号