& Quot; $ (document). ready (function () {}) & quot; letter in Jquery

Source: Internet
Author: User

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:
$ ("Div p"); // (1)
$ ("Div. container"); // (2)
$ ("Div # msg"); // (3)
$ ("Table a", context); // (4)
$ ("# MyId"); // (5)

The first line of code gets all <p> elements under the <div> label. The second line of code gets the <div> element whose class is container, and the third line of code gets the element whose id is msg under the <div> label. 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)

<Body onload = "alert ('hello');"> (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.

Related Article

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.