1

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'});

6 Answers 6

10

Try

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

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});
2

or

$('#wrapper').css({height:newheight+'px');
1
  • 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 Jan 8, 2010 at 15:24
2

This should work:

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

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

Or

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

So many ways to do the same thing. height method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.