Differences between jQuery $ (document). ready (function () {}) and jswindow. onload

Source: Internet
Author: User
$ (Document ). ready (function () {}) indicates that the DOM document structure is loaded and jQuery. js is also executed after loading, excluding images and other non-text media resources, $ (document ). ready (fu

$ (Document). ready (function (){})Indicates that the DOM document structure is loaded and jQuery. js is also executed after loading, excluding images and other non-text media resources, $ (document ). the scaling method of ready (function () {}) is as follows:
$ (Function () {...}) and $ (). ready (function (){...})
Window. onloadIt indicates that the page and all resources including images are loaded and executed.
At this level, $ (document). ready (function () {}) is much better than window. onload, because the Loading Order of a page is as follows:Domain name resolution-loading html-loading js and css-loading ImagesAnd other information.
Note the following special cases:
Because $ (document ). ready (function (){...}) it starts execution once the DOM node is loaded. But how to reference other JS scripts on the page and modify some DOM node structures? $ (document) at this time ). ready (function (){..}) the actual node may not be detected. Of course, you can use setTimeout () or setInterval to solve the problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.