Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
25
rated 0 times [  30] [ 5]  / answers: 1 / hits: 19665  / 15 Years ago, sat, july 18, 2009, 12:00:00

I'm unable to get the height of a page in javascript when the page is larger than the screen.



I thought this would get me the right height:



$(document).height();


but that only gets the height of the screen, same as:



$('body').height();


same as:



document.offsetHeight;


For some reason all these examples only return the height of the screen. Can somebody help?


More From » jquery

 Answers
14

Using jQuery (which you did specify), $(document).height() will return exactly what you're asking for.



To clarify the usage of the height() method:



$('.someElement').height(); // returns the calculated pixel height of the element(s)
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document


I suspect, that if $(document).height() is not working for you, something is wrong. You may be:




  1. Calling it too early. Like, before the DOM is ready

  2. Have some uncleared floats that are not causing some block level elements to expand to their real height. Thus messing up height calculations.

  3. Have something critical absolutely positioned. Absolutely positioned elements do not contribute towards height calculations of their parent elements.


[#99101] Tuesday, July 14, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nadineannabellet

Total Points: 464
Total Questions: 94
Total Answers: 97

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
;