Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery $(window).height() is returning the document height

Tags:

jquery

I'm sure there is a simple error I'm making, but I am simply alerting $(window).height() and it returns the same value as $(document).height().

I am on a 13" MBA and my window height of my browsers when maximised between 780px - 820px (roughly) but each time it returns a window height identical to that of document height. In every case on the site I am working on it is over 1000px.

What is going on here?

alert($(window).height()); alert($(document).height());  
like image 559
Fraser Avatar asked Aug 24 '12 04:08

Fraser


People also ask

How to get document height in jQuery?

jQuery height() Method The height() method sets or returns the height of the selected elements. When this method is used to return height, it returns the height of the FIRST matched element. When this method is used to set height, it sets the height of ALL matched elements.

How to get height of window in jQuery?

This method is also able to find the height of the window and document. $( document ). height();

How do you find 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 do I set dynamic height in jQuery?

Answer: Use the JavaScript height() method You can set the height of a <div> box dynamically using the jQuery height() method.


1 Answers

With no doctype tag, Chrome reports the same value for both calls.

Adding a strict doctype like <!DOCTYPE html> causes the values to work as advertised.

The doctype tag must be the very first thing in your document. E.g., you can't have any text before it, even if it doesn't render anything.

like image 96
Tom Hubbard Avatar answered Oct 06 '22 03:10

Tom Hubbard