Search code examples
jqueryvariableslive

Getting live height of html with JQuery?


How can I get a live variable of the html element in JQuery?

So far I have been using this,

var htmlHeight = $('html').height();

This has worked fine, but I have recently added some slideToggle divs into my webpage which add a lot of extra height to my document, and the current variable is out by quite a lot if the slideToggle divs are active.

I have tried to add a live event to it but it fails as I just need the variable and do not need to bind it to anything such as click or hover.


Solution

  • Why dont you use a function to get the height each time its needed with your jquery

    function curHeight(){
       return $('html').height();
    }
    

    so whenever you want the height of the html just call the function and it should give you the current height of the html document.