0

I am trying to have the same height for the div '.impress' as for the div '.page' but the height is not displayed correctly for my '.impress' div (the '.impress' is to small).

JQuery:

var getHeight = $('.page').height();
$(".impress").css('height', getHeight+200);
4
  • what error do you get?
    – Ejaz
    Commented Apr 12, 2013 at 18:55
  • 1
    When using the css function you are setting the raw style. height needs units like px: .css('height', getHeight+200+'px').
    – Ross Allen
    Commented Apr 12, 2013 at 18:57
  • Thank, you I added all this but when I refresh my page it still shows the old preview (I tested it but it stays the same all the time) Commented Apr 12, 2013 at 19:00
  • Finished fiddle Commented Apr 13, 2013 at 8:18

3 Answers 3

3

You should use jquery's height() method to set the height:

$(".impress").height(getHeight+200)

Or, if you are using css('height',...) be sure to include units, in your case:

$(".impress").css('height', (getHeight+200) + 'px')
4
  • he is using jQuery to set the height of .impress
    – Ejaz
    Commented Apr 12, 2013 at 18:56
  • Thank, you I added all this but when I refresh my page it still shows the old preview (I tested it but it stays the same all the time) Commented Apr 12, 2013 at 19:04
  • @JSHelp, can you add console.log('getHeight=' + getHeight); line in the code before setting the height and then run the page and check the log output?
    – Vlad
    Commented Apr 12, 2013 at 19:14
  • Works all fine now. Thank you for all your help Commented Apr 13, 2013 at 8:17
0

Have you ensured that the DOM is loaded and ready before accessing the Height of .impress?

Make sure this is taking place in $(document).ready(function() {}); to ensure .impress has been laid out and has a height.

1
  • Thanks for the hint but i have that Commented Apr 12, 2013 at 19:02
0

First make sure that the .page exists.

if($('.page').length){
    var getHeight = parseInt($('.page').height());
    $(".impress").css('height', getHeight+200);
}
else{
    alert('oops');
}

Update:

and if $('.page') exists then make sure it has some height. A parent with all children floated might have height = 0

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.