Differences between window. onload and $ (document). ready () _ javascript skills

Source: Internet
Author: User
This article mainly introduces window. onload and $ (document ). the difference between ready () and the example analyzes the differences between the two in the use of page elements. For more information, see the example in this article. onload and $ (document ). ready. Share it with you for your reference. The specific analysis is as follows:

Window. onload is a function in Javascript, meaning: wait for the webpage to load all content (including images );
And $ (deleetn ). ready () can be executed after all DOM structures in the web page are drawn. it may be because the elements associated with the DOM have not been fully loaded, so it is faster;

For example, a simple example:

Window. onload = function () {alert ('I am No.1') ;}; window. onload = function () {alert ('I am no.2 ');}

According to the preceding meaning, only "I am No. 2" can be output"

Replace:

$ (Document ). ready (function () {alert ('I am No.1') ;}); $ (document ). ready (function () {alert ('I am No. 2 ');});

Result output I am No.1, I am No. 2

I hope this article will help you design javascript programs.

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.