What is the major difference between $(window).width()
vs $(document).width()
in jQuery?
Whether window denotes the browser and document represents
Well, the
window
is the first thing that gets loaded into the browser. Thiswindow
object has the majority of the properties likelength
,innerWidth
,innerHeight
,name
, if it has been closed, its parents, and more.What about the document object then?
The
document
object is your html document that will be loaded into the browser. Thedocument
actually gets loaded inside thewindow
object and has properties available to it like title, URL, cookie, etc. What does this really mean? That means if you want to access a property for thewindow
it iswindow.property
, if it isdocument
it iswindow.document.property
which is also available in short asdocument.property
.
So in conclusion the document could be smaller than the window.
FROM: http://eligeske.com/jquery/what-is-the-difference-between-document-and-window-objects-2/