tags:

views:

29

answers:

3

How to get scrollHeight value from document?

Getting undefined currently.

Anyone? :)

+4  A: 
$(document).height() //returns window height

$(document).scrollTop() //returns scroll position from top of document
Bob Gregor
I was thinkig the same way, but why doesconsole.log($(this).scrollTop()) = 1187console.log($(this).height()) = 1762it differs so much? For 575px if I have scrolled to the bottom of the page.Where are those 575px gone? Scroll bar can't be 576px :)
Beck
Baaah again my fault. I was looking at scrollbar with opened firebug window.Ofc it can be 576px now. :)Thanks i guess topic is closed.
Beck
+1  A: 

Something like this should solve your problem:

$.getDocHeight = function(){
     var D = document;
     return Math.max(Math.max(D.body.scrollHeight,    D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight));
};

alert( $.getDocHeight() );

Ps: Call that function every time you need it, the alert is for testing purposes..

Zuul
A: 

document.getElementById("elementID").scrollHeight