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
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
Share Improve this question edited Jun 13, 2012 at 21:02 dmck asked Jun 13, 2012 at 20:58 dmckdmck 7,8617 gold badges45 silver badges79 bronze badges 4- Without seeing a test case, we can only have wild assumptions about what can cause this. Please create a demo or show the page. Here is a demo that shows it working. Your turn. – kapa Commented Jun 13, 2012 at 21:04
- @bažmegakapa It is a large application I am unable to post, I can attempt to create a repro, however, I was wondering if there were cases where jquery cannot determine the height. – dmck Commented Jun 13, 2012 at 21:11
- It's always difficult (mostly impossible?) to find a bug when you cannot see the code and the program running. – kapa Commented Jun 13, 2012 at 21:14
- 2 Are you running this after the page has loaded? – epascarello Commented Jun 13, 2012 at 21:28
2 Answers
Reset to default 14Simply 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
Use this-
$("body").css("height")
well i will say jquery is not needed-
this.style.height;//it will not work if you add it as inline js.