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.