$ (window) .height () vs $ (document) .height

I have a problem with the wrong height using

$(window).height(); 

and got a similar question here

In my case, when I try

 $(document).height(); 

seems to return me the correct result

window height returns 320

while the height of the document returns 3552!

I found this question

But in my case the window is already loading completely, as I call the height function after several ajax operations

So what is the best way to know the height of the current window?

Edit:

enter image description hereenter image description here

+53
jquery
Dec 26
source share
5 answers

Well, you seem to be mistaken in both for what they do.

$(window).height() gets the pixel value of the browser window window . For web browsers, the viewport here is the visible part of the canvas (which is many times smaller than the document that is being rendered).

$(document).height() returns the pixel value of the document . If the actual height of the document is less than the height of the viewport, then instead it will return the height of the viewport.

Hope that clears up a bit.

+100
Dec 26 '12 at 5:59
source share

AFAIK $(window).height(); returns the height of your window, and $(document).height(); returns the height of the document

+7
Dec 26 '12 at 4:18
source share

It fixed me

 var width = window.innerWidth; var height = window.innerHeight; 
+5
Oct 05 '16 at 15:28
source share

You need to know what this means about the document and the window.

  • The window object is an open window in the browser. Click here
  • The Document object is the root of the document tree. Click here
0
Dec 26 '12 at 5:40
source share

$(document).height: if your device height larger. There is no scroll on your page;

$(document).height: Suppose you do not scroll and return this height ;

$(window).height: return the height page to your device.

-2
Sep 13 '15 at 16:49
source share



All Articles