"$ (Document). ready (function () {})" function usage in Jquery _ jquery

Source: Internet
Author: User
This article focuses on & quot; $ (document) in Jquery ). ready (function () {}) & quot; the usage of the function is described in detail. If you need it, please refer to it, I hope to help you. Jquery is an excellent Javascr into pt framework. $ is the declaration of the jquery library. It is very unstable (I often encounter it). It is a stable way to write jQuery. noConflict (); jQuery (document ). ready (function (){});

The advantage of using jQuery is that it encapsulates various browser versions for DOM objects (javascript DOM objects, You should know.

For example, jquery:
$ ("P"); // (1)
$ ("P. container"); // (2)
$ ("P # msg"); // (3)
$ ("Table a", context); // (4)
$ ("# MyId"); // (5)

The first line of code gets all

Under the tag

Element. The second line of code gets

Element, the third line of code to get

The element whose id is msg under the tag. The fourth line of code shows all the connected elements in the table with context as the context. Code the fifth line to obtain all elements whose id is myid.

If you are familiar with CSS, you will find these statements very familiar! By the way. Exactly. See the secret. Jquery finds the elements in the Dom object in this way. It is similar to the CSS selector.

Now let's answer your specific question.

$ (Document). ready (function (){
Alert ("hello ");
}); (1)

(2)

The above two sections of code are equivalent. But the advantage of code 1 is that performance is separated from logic. In addition, you can perform the same operation in different js files, that is, $ (document). ready (fn) can be repeated on a page without conflict. Basically, many plug-ins of Jquery use this feature. Because of this feature, multiple plug-ins are used together and will not conflict during initialization.

If we
$ (Document). ready (function (){
Added content
});
Add content $ (". btn-slide"). click (function (){
Alert ("You have clicked the connection where the class is btn-slide in the label ");
});

This means that when we click the super connection of class = btn-slide, the "you clicked the connection where class is equal to btn-slide" dialog box is displayed.

So convenient and easy to use, it is a good choice to use jquery.

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.