window height is getting the length of the html document rather than the size of my browser window.
Do you know where I'm going wrong?
Here's my script:
$(document).ready(function() {
alert($( window ).height());
});
I also have at the top of my doc which I've read can cause issues:
<!DOCTYPE html>
window height is getting the length of the html document rather than the size of my browser window.
Do you know where I'm going wrong?
Here's my script:
$(document).ready(function() {
alert($( window ).height());
});
I also have at the top of my doc which I've read can cause issues:
<!DOCTYPE html>
Share
Improve this question
asked May 8, 2014 at 15:51
panthropanthro
24.1k70 gold badges200 silver badges349 bronze badges
5
|
2 Answers
Reset to default 16window.innerHeight
$(document).ready(function() {
alert(window.innerHeight);
});
I think it must be an old version of jQuery that is buggy? Using 1.6.4 (the oldest that jsfiddle supports), I get the right behavior. See JSFiddle
If you can't figure it out, you can use window.innerHeight
, I try to use jQuery only if it takes less code, which it doesn't in this case.
div {
height: 2000px;
}
// onload
alert($(window).height());
// outputs window height, not 2000
clientHeight
– marekful Commented May 8, 2014 at 15:52jQuery.height()
is supposed to correctly get the height of browser window, not the HTML document. – Ruan Mendes Commented May 8, 2014 at 16:18document.body.clientHeight
(as recommended by @marekful) if you want to calculate the height of the whole document. – Govind Rai Commented Jan 4, 2017 at 18:06