Differences between document. ready and window. onload

Source: Internet
Author: User
This article mainly introduces document. ready and window. for the difference between onload, if you need it, you can refer to Javascript to execute some operation on it only after the DOM element has been defined. This problem is detailed in the "javascript execution sequence" http://www.jb51.net/article/44577.htmbroke.

JQuery uses document. ready to ensure that the code to be executed is executed when the DOM element is loaded. For example, in the document "jQuery basics-how to get started", I used the following jQuery code:

The Code is as follows:




This Code indicates that a warning message is displayed after the Dom Tree is loaded.

Document. ready () and traditional methodsSimilarly, onload () occurs only after the page is loaded. This includes loading of DOM elements and other page elements (example,

Therefore, the execution speed of the document. ready () method is faster than that of the onload () method.

Note the following two points (from the jQuery document ):

1. Make sure thatThe onload event of the element does not register a function. Otherwise, the $ (document). ready () event may not be triggered. (
I tried to use the following example to demonstrate this situation, but it was not successful, so I think this is only possible .)

The Code is as follows:




My second jQuery






Simple jQuery Example 2

I wowould like to say:





2. You can use the $ (document). ready () event infinitely on the same page. The registered functions are executed sequentially.
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.