Jquery Dom loading and document loading

Source: Internet
Author: User

Yesterday, zchiy2k asked me how jquery handled Dom loading and document loading. I didn't answer the question at the moment, in development, I have never handled the issue of waiting for all the page content to be loaded. In fact, in jquery, processing the loading of documents is usually a very common load event, but listening to Windows. I sorted it out today. By the way, I despise myself for front-end development so long that I don't even know this.

Full page loading means that all content on the page is fully loaded, including windows, frames, objects, and images. In jquery, this goal is achieved by listening to the load events of windows. This event will delay the execution of JavaScript code because the page may contain a large number of images or even flash.

$ (Window). Load (function () {alert ('page Load completed ');});

If the library is not used for development, listening to this event with native Javascript is also very simple:

Window. onload = function () {alert ('page Load completed ');}

The most common practice is to execute JavaScript code when Dom construction is complete, so that the code can be executed as soon as possible on the premise that the page elements are complete, the ready function may be the first class for most people who have studied jquery.

$ (Document ). ready (function () {alert ('dom loaded completion ') ;}); // normally we are lazy: $ (function () {alert ('dom loaded completion ');});

For those who intend to use native JavaScript for development, domready is a very rigorous and reliable microlibrary that checks whether the Dom is ready.

From: http://www.jsmix.com/javascript/document-ready-window-load.html

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.