JQuery $ ("body"). height () returns undefined

I have a call like this:

$("#ContextMenuModal").height($("body").height()); 

However, $("body").height() returns undefined when I view it in Firebug.

What would cause jQuery to return undefined for body height?

I am using jQuery 1.4.1.

Edit:

This is inside iFrame

+4
source share
2 answers

Just use

 $(document).height() // - $('body').offset().top 

and / or

 $(window).height() 

instead of $ ('body'). height ()

To expand the bit,

 $(window).height(); // returns height of browser viewport $(document).height(); // returns height of HTML document 

As Bajmegakapa points out, there is a slight difference, albeit a few pixels. The true body height can be calculated by subtracting the body offset from the height of the document (as I mentioned above):

 $(document).height() - $('body').offset().top 
+10
source

Use it -

  $("body").css("height") 

Ok, I will say that jquery is not needed -

 this.style.height;//it will not work if you add it as inline js. 
0
source

All Articles