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

Asked

Viewed 200 times

5

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

I’ve tried calling directly $("html").height(), but it didn’t work either.

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

  • Have you tried the answers to that other question? If possible post your code - or maybe a link to your site - because without knowing its structure it is difficult to know what might be happening. When you say "different" do you mean quite different (like, with practical implications) or only marginally different (browsers sometimes calculate sizes slightly differently)? Finally, there are elements with 100% height or Divs with different scroll pattern?

2 answers

1


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

$(Document). ready(Function() { Alert($(Document). height()); });

But I found that when using $(Document). ready, certain information was lost, since it runs when html is loaded and DOM is ready, so I used $(window). load that runs only when the entire page is fully loaded, including all frames, Objects and images.

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

$(window). load(Function() { var test = $(Document). height(); Alert(test); });

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

0

Do so:

$(document).outerHeight()

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.