Mateo
Mateo

Reputation: 177

How to change iFrame style

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

Answers (4)

Sampson
Sampson

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

Albireo
Albireo

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

Michael Mior
Michael Mior

Reputation: 28753

$("#myiframe").css({"width": 104});

Upvotes: 3

genesis
genesis

Reputation: 50966

try

$("#myiframe").attr("width", "104px");

Upvotes: -1

Related Questions