Henrik Petterson
Henrik Petterson

Reputation: 7094

jQuery adjusting iframe height

This code was passed to me. It makes my iframe set to 100% height of the screen:

jQuery(document).ready(function(){var height = $(window).height();
             $('iframe').css('height', height)
         });

I am new to javascript. How can I edit this code to make it set to 90% height rather than 100%? Also, this code targets all iframes, is there any way to make it target a specific iframe (by its ID or NAME value)? You can fiddle with this code here if you wish: http://jsfiddle.net/VurLy/

Upvotes: 7

Views: 38056

Answers (3)

Scott Selby
Scott Selby

Reputation: 9570

in jquery you can identify which elemtents you want many different way , most popular is by the id like this $('#scoop') or by class , like this $('.scoop') - if the class was scoop

so that is how you identify the specific iFrame you want , then change the height like this

 jQuery(document).ready(function() {
   var height = $(window).height();
   $('#scoop').css('height', '90%'); 
});

Upvotes: 0

mittmemo
mittmemo

Reputation: 2080

jQuery(document).ready(function(){
    $('#YOUR_FRAME_ID_HERE').css('height', '90%')
});​

Upvotes: 2

Ry-
Ry-

Reputation: 224862

Multiply it by 90%?

jQuery(document).ready(function() {
    var height = $(window).height();
    $('iframe').css('height', height * 0.9 | 0);
});

As for targeting by ID or name, just pass the appropriate selector to $ instead of 'iframe'.

Upvotes: 11

Related Questions