Javascriptdocument the difference between load and document ready

Source: Internet
Author: User

Page loading completed there are two kinds of events, one is ready, indicating that the document structure has been loaded complete (貋 pictures and other non-text media files), and the second is the onload indicates that the page contains pictures and other files including all the elements are loaded complete.1. Different execution times: In the literal sense, the $ (document). Ready () is the documentation. That is, the browser has parsed the entire HTML document, the DOM tree has been established, then you can use the class attribute or id attribute, etc. to the DOM operation. and $ (window). Load () is the entire page has been loaded. The difference with the former is that the DOM tree has been established, but the page does not have to be loaded, such as some large pictures, loading completed will take a certain amount of time, but after the page is loaded, the DOM must be built up, but some text or image links need to be loaded before the document is finished, When the DOM tree is established, it is necessary to use $ (document). Ready ().

2. The number of times that can be executed is different:

$ (document). Ready () can appear multiple times in JavaScript code, and functions or code inside can be executed, while $ (window). Load () can only appear once in JavaScript code, if there are multiple $ (window ). Load (), then only the last $ (window). The function or code inside the load () is executed, before the $ (window). Load () will be overwritten;

3. The efficiency of implementation is different:
to add the onclick attribute node to the element node of the DOM, use $ (document). Ready () is more efficient than using $ (window). Load (), but at some point you have to use $ (window). Load (), As previously written app download, if you want to close this download box, you have to complete the download box after loading, you can click the Close icon, the app download box to perform hidden.

<script>$(document).ready(function(){  $(".the_body a").attr("onclick","alert(‘test‘)");});$(window).load(function(){   $(".close_btn").click(function(){        $("#app_down").hide();    });});</script>

Source: http://blog.csdn.net/liucyccdt2013/article/details/41749377

<wiz_tmp_tag id= "Wiz-table-range-border" contenteditable= "false" style= "Display:none;" >



From for notes (Wiz)



Javascriptdocument the difference between load and document ready

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.