Reputation: 37876
I know, this thing has been asked like 2 trillion times, but i cannot still get done. the iframes are generated dynamically inside the source which I get from external feed.
my jquery is:
$(function(){
$('iframe').each(
function(index, elem) {
elem.setAttribute("width","250");
}
);
});
this code is not being able to set the width of iframe.
and one more thing: I inspected the iframe attributes, and there are NOT editable in browser unlike other css style - which means, my jquery cannot also set it after DOM is ready
what the heck? is there any workaround for this?
Upvotes: 0
Views: 1012
Reputation: 802
try:
$(function(){
$('iframe').each(
function(index, elem) {
elem.css({ "width":"250px !important" });
}
);
});
Upvotes: 0
Reputation: 4514
There is a very simple way of assigning "width or height" to any element at run-time, and that's using ".width()
and .height()
" method of jQuery.
Refer:
Here is an example:
<script type="text/javascript">
$(document).ready(function () {
$("iframe").width(500);
$("iframe").height(500);
});
</script>
Here is another stackoverflow question for iframe width where you can find good explanation in the answer if you are using multiple iframes : Change iframe width and height using jQuery?
Upvotes: 0
Reputation: 5148
Works for me with
$('iframe').each(function(){
$(this).width( w );
});
Upvotes: 0
Reputation: 18891
$('iframe').each(function(){
$(this).width(250);
});
Docs: http://api.jquery.com/each/ and http://api.jquery.com/width/#width-value
Upvotes: 1