Difference between $(window).width() vs $(document).width()

后端 未结 6 1012
灰色年华
灰色年华 2020-12-08 03:52

What is the major difference between $(window).width() vs $(document).width() in jQuery? Whether window denotes the browser and document represents

6条回答
  •  执笔经年
    2020-12-08 04:31

    Well, the window is the first thing that gets loaded into the browser. This window object has the majority of the properties like length, 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. The document actually gets loaded inside the window 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 the window it is window.property, if it is document it is window.document.property which is also available in short as document.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/

提交回复
热议问题