Chwebo Chwebo - 11 days ago 8
HTML Question

jQuery - Get the total height of the page

I checked this and even other websites for this question and I also looked into the documentation of jQuery, but unfortunately I didn't find a solution that worked for me, so I'm opening a new thread...

I have to get the total height of the page for an other function but I'm not able to get it.

$(body).height();
detects a height of 1085px but the correct height is 1774px. On other pages of the website the values are of course different, but jQuery never gets the correct height.

I tried to get the right height with the following and they all failed:
$('#site-body').height();
,
$('#site-body').outerHeight();
,
$('#site-body').outerHeight(true);
,
$(document).height();


If anyone of you knows a different way to get the height of the page or if anyone has an idea why this doesn't work, please let me know.

Regards, chwebo

Answer

I included the function $('body').height(); snippet in a scroll function and this works well.

$(document).ready(function(){
   $(window).scroll(function(){
      var pageHeight = $('body').height();
   }
}

I have no idea why this happens, but if anyone has the same issue, try this.

Comments