Usage of jQuery ready () method

Source: Internet
Author: User

JQuery's ready method is frequently used in development and serves as our body onload. It is the code that runs when the page DOM is ready, the most common one is to bind the ready event to the document before DOM rendering and loading, and then run the event only after the DOM of the page is ready.

Ready of jQuery has the following usage:

The most common and standard ready Method
$ (Document). ready (){
});
Short for jQuery ready ()
$ (Function (){
});
This is because if the first parameter of the jQuery selector is null, the default value is document.

The ready () method is not recommended.
$ (). Ready (handler );
As mentioned in the jQuery1.4 announcement, this method is still retained in jQuery1.4 but not recommended. In addition, the ready of jQuery1.3 will return a jQuery object, but not in jQuery1.3.

Ready Method for Solving jQuery ($) Library conflicts

This method is generally used to handle conflicts between jQuery $ and other libraries. You can use jQuery. in noConflict (), we can directly use jQuery in code instead of $, but we are used to $. What should we do? See the following code:

JQuery. noConflict ();
JQuery (function ($ ){
Alert ($ ("# ready1" cmd.html (); // you can use $
});

Postscript
JQuery's ready method is not recommended in development, because after binding the ready event, jQuery needs to add a DOMContentLoaded listening event, which has a certain impact on page loading and rendering, we recommend that you use jQuery ready only when you have.

In actual development, we recommend that you put the functions to be executed in ready after the dom html code, that is, execute handler after DOM rendering, or directly put the code at the end of the page.

Original article: http://www.js8.in/603.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.