$ (document) .height () does not return the correct value

5

I'm trying to get the $(document).height() size of my site, but the value shown is sometimes different than the size of the HTML (in preview element) it shows.

I've tried calling directly $("html").height() , but it also did not work.

I found this question answered, but I do not know how to apply the answer to test .

    
asked by anonymous 22.01.2015 / 04:54

2 answers

1

$ (document) .height () takes the right value, but I was trying to get it when the document was ready, which in the case is how the code starts:

$ (document) .ready (function () {     alert ($ (document) .height ()); });

But I discovered that while using $ (document) .ready, certain information was lost, since it executes when the html is loaded and the DOM is ready, so I used $ (window) .load that executes only when the entire page is fully loaded, including all frames, objects and images.

So the code that works the way I wanted it is:

$ (window) .load (function () {     var test = $ (document) .height ();     alert (test); });

That is, when the page loads completely, the code triggers an alert with the total height of the document (html) value.

    
24.01.2015 / 00:09
0

Do this:

$(document).outerHeight()

This returns the value of the element counting also with the padding

    
22.01.2015 / 13:20