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
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.
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.
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.
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();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With