Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the body height?

I am using jQuery 1.4.1.

Edit:

This is inside an iFrame

like image 621
dmck Avatar asked Jun 13 '12 20:06

dmck


People also ask

What is height in jQuery?

In jQuery, height method is used to get the height of any element in HTML. The height method sets and returns the height of the HTML elements. Method 1: The height() method returns the first matched element's height, But the height(value) method sets all matched elements height.

How can I increase my body height?

Stand tall with shoulders flat against the wall and slide a flat object, like a book or cutting board, along the wall until you can bring it down to make firm contact with the top of your head. Mark under the object where it lands. Use a tape measure to determine your height from the floor to the mark.

How do I check the height of a document?

Getting the Height of a Document To get the height of a document, we can get the max of the scrollHeight , offsetHeight , or clientHeight properties. The document can be stored in the document. body or document. documentElement properties depending on the browser used.

How does jQuery calculate window height?

height() method is recommended when an element's height needs to be used in a mathematical calculation. This method is also able to find the height of the window and document. $( document ). height();


1 Answers

Simply use

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

and / or

$(window).height()

instead $('body').height()

To expand a bit,

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

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

$(document).height() - $('body').offset().top
like image 189
Norse Avatar answered Sep 22 '22 19:09

Norse