Detailed use of the "$ (document). Ready (function () {})" function in jquery _jquery

Source: Internet
Author: User
Tags jquery library

jquery is a good JAVASCRĪPT framework, $ is the jquery library statement, it is very unstable (I often met), change a stable writing jquery.noconflict (); JQuery (document). Ready (function () {});

The advantage of using jquery is that it wraps the operation of various browser versions of Dom objects (JavaScript DOM objects you should know, that's it).

Like jquery:
$ ("div p"); (1)
$ ("Div.container"); (2)
$ ("div #msg"); (3)
$ ("Table A", context); (4)
$ ("#myId"); (5)

The first line of code gets the <p> element under all <div> tags. The second line of code gets the <div> element with class container, and the third line gets the element with the ID msg below the <div> tag. The four lines of code get all the connection elements in the table with context. Line five gets all the elements with ID myID

If you are familiar with CSS, you will find these wording familiar! That's right. Is. See the mystery. jquery is the way to find elements within a DOM object. Similar to the CSS selector.

Now, answer your specific questions.

$ (document). Ready (function () {
Alert ("Hello");
});(1)

<body onload= "alert (' Hello ');" > (2)

The above two pieces of code are equivalent. But the benefit of code 1 is to do performance and logical separation. And you can do the same thing in different JS files, that is $ (document). Ready (FN) can appear repeatedly on one page without conflict. Basically, many of jquery's plugin take advantage of this feature, and because of this feature, multiple plugin are used together and there is no conflict during initialization.

If we are
$ (document). Ready (function () {
What to add
});
Add content $ (". Btn-slide"). Click (function () {
Alert ("You clicked the class equals Btn-slide connection" in the A tag);
});

Indicates that when we click on Class=btn-slide's Super Connection, "you clicked the connection with class equals btn-slide in Tab A" dialog box.

So easy to use, so using jquery is a good choice.

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.