How to add height to wrapper with jQuery?

23,932

Solution 1

Try

$('#wrapper').css("height", newheight);

Solution 2

or

$('#wrapper').css({height:newheight+'px');

Solution 3

This should work:

$('#wrapper').css({'height':newheight});

Solution 4

you are assigning a string value to your height, all you need to remove quotes and put simply a variable containing value. like

var newheight = getPageSizeWithScroll() + 30;

$('#wrapper').css('height':newheight);

Solution 5

You're setting the height to the string 'newheight', instead of the value of newheight. Simply get rid of the quotes:

$('#wrapper').css({'height':newheight});
Share:
23,932
shin
Author by

shin

IB Diploma and MYP mathematics teacher who loves coding.

Updated on July 09, 2022

Comments

  • shin
    shin almost 2 years

    I need to add css height to each page dynamically with jQuery.

    So far I got the following code, but it does not add height to #wrapper.

    function getPageSizeWithScroll(){
    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    arrayPageSizeWithScroll = yWithScroll;
    //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
    return arrayPageSizeWithScroll;
    }
    var newheight = getPageSizeWithScroll() + 30;
    
    $('#wrapper').css({'height':'newheight'});
    
  • Mark Schultheiss
    Mark Schultheiss over 14 years
    or +'em' or any other if you choose not to go with pixels (of course the logic would change from the 30 value), +1 for this tidbit