0

I use jquery ver 1.10.2 and I need to know the height of the body, not of the window(!). I use the following code:

<script>
     window.onload=function(){
         alert($("body").height());
     }
 </script>

But I get 0. Can you help me?

EDIT: I have checked - document height can't be less that window height, but I need to know the difference between body height and window height, when body height < window height as I want to use js to make sticky footer.

1 Answers1

0

Simply use

$(document).height() // - $('body').offset().top

and / or

$(window).height()

instead

$('body').height()

To expand a bit,

$(window).height();   // returns height of browser viewport
$(document).height(); // returns height of HTML document

As bažmegakapa points out, there is a slight difference, albeit a few pixels. The true height of the body can be calculated by subtracting the body offset from the document height (like I mentioned above):

$(document).height() - $('body').offset().top
DeDevelopers
  • 581
  • 1
  • 7
  • 25