$ Is a special name of the jQuery "class". $ () constructs a jQuery object. Therefore, "$ ()" can be called the jQuery Constructor (in my opinion, haha !). 1. $ () can be $ (expresion), that is, the css selector, Xpath, or html element, that is, matching the target element through the above expression.
For example, $ ("a") constructs a jQuery object using the CSS selector-it selects all the tags. For example:
$ ("A"). click (function (){...})
Is the trigger event when you click any link on the page. Specifically, jQuery uses this label to construct an object $ ("a"), and the function click () is an (event) method of this jQuery object.
For example, there is such an HTML code:
The Code is as follows:
One
Two
Three
JQuery
The operation of this section of HTML is as follows:
Alert ($ ("p> p" example .html ());
$ () Is a query expression, that is, using a query expression such as "p> p" to construct a jQuery object, and then the "html () "display the html content, that is, the [two] of the preceding HTML code segment. Another example is:
$ ("
Hello
"). AppendTo (" body ");
$ () Is a string that constructs a jQuery object with such a string, and then.
2. $ () can be $ (element), which is a specific DOM element. For example, common DOM objects include document, location, and form. Such as a line of code:
$ (Document). find ("p> p" example .html ());
The document in $ () is a DOM element.
Of
And display
.
3. $ () can be $ (function), which is a stenographer of $ (document). ready. For example, the common form is as follows:
$ (Document). ready (function (){
Alert ("Hello world! ");
});
Deformation:
$ (Function (){
Alert ("Hello world! ");
});
JQuery has two methods for selecting elements in HTML documents:
1) For example, $ ("p> ul a") indicates a tag in ul tag of p.
However, $ ('P> ul ') and $ ('P ul') are different,
$ ('P> ul ') Yes
Find