Jquery is an excellent Javascrīpt framework. $ is the declaration of the jquery library. It is very unstable (I often encounter it). Change to a stable writing method jQuery.noConflict(); jQuery(document).ready(function( ){});
The advantage of using jQuery is that it packages the operations of various browser versions on DOM objects (you should know the DOM objects of javascript, this is it).
For example, jquery writing:
$("div p"); // (1)
$("div.container"); // (2)
$("div #msg" ); // (3)
$("table a",context); // (4)
$("#myId"); //(5)
The first line of code gets all the
elements under the
If you are familiar with CSS, you will find these writing methods very familiar! Right. Exactly. You can see the secret. This is how jquery finds the elements in the Dom object. Similar to CSS selectors.
Let’s answer your specific questions now
$(document).ready(function(){
alert("hello");
});(1)
The above two pieces of code are equivalent. But the advantage of code 1 is to separate performance and logic. And the same operation can be done in different js files, that is, $(document).ready (fn) can appear repeatedly in a page without conflict. Basically, many plugins of Jquery make use of this feature. Because of this feature, multiple plugins can be used together without conflict during initialization.
If we add content in
$(document).ready(function(){
Added content
});
Add content$(".btn-slide").click(function (){
alert("You clicked the link with class equal to btn-slide in the a tag");
});
means that when we click the super link with class=btn-slide, the dialog box "You clicked the link with class equal to btn-slide in the a tag" pops up.
So convenient and easy to use, so using jquery is a good choice.