The sharp jQuery key points are summarized (2) DOM operations in jQuery. For more information, see. 1. Search for element nodes
Var $ x =$ ("Selector"). text ()
2. Search for Attribute nodes
Var $ x =$ ("Selector"). attr ("property ")
3. Create a node
Var $ x = $ ("html ")
4. Insert nodes
$ ("Selector"). append ()
Append content to each Matching Element
$ ("Selector"). appendTo ()
Equivalent to the. append () operator interchange between left and right
$ ("Selector"). prepend ()
Forward content to each Matching Element
$ ("Selector"). prependTo ()
Equivalent to the. prepend () operator interchange between left and right
$ ("Selector"). after ()
Insert content after each Matching Element
$ ("Selector"). insertAfter
Equivalent to the. after () operator interchange between left and right
$ ("Selector"). before ()
Insert content before each Matching Element
$ ("Selector"). insertBefore ()
It is equivalent to interchange between the left and right sides of the. before () operator.
5. Mobile nodes
P70 examples in this book:
The Code is as follows:
Script
Var $ one_li = $ ("ul li: eq (1)"); // get
2nd of the nodes
- Element Node
Var $ two_li = $ ("ul li: eq (2)"); // get
3rd of the nodes
- Element Node
$ Two_li.insertBefore ($ one_li); // move a node
Script
6. delete a node6.1 remove () method
$ ("Selector"). remove ()
The remove () method deletes all child nodes of the selector. After the elements are deleted using the remove () method, they can still be used. In addition, the remove () method can also pass parameters.
To selectively Delete elements, such as $ ("ul li"). remove ("li [title! = Xxx] ");
6.2 empty () method
$ ("Selector"). empty ()
Clear all child nodes of selector
7. Copy nodes
$ ("Selector"). clone ()
For example, $ (this). clone (). appendTo ("ul "). To make the copied new element carry the behavior of the original element, you must pass the parameter true. For example, $ ("selector"). clone (true)
8. Replace nodes
$ ("Selector"). replaceWith ()
Replaces all matched elements with specified HTML or DOM elements.
$ ("Selector"). replaceAll ()
It is equivalent to interchange between left and right of the. replaceWith () operator.
9 Package nodes
$ ("Selector"). wrap ()
Enclose all matching elements separately
$ ("Selector"). wrapAll ()
Wrap all matching elements with one element
$ ("Selector"). wrapInner ()
Enclose the child content (including text nodes) of each Matching Element with other structured tags.
10 attribute operations
$ ("Selector"). attr ()
Get (a property parameter) and set element attributes (two parameters, property and value), such as $ ("p"). attr ("title", "your title "). If
Multiple attributes, such as $ ("p"). attr ({"title": "your title", "name": "test "})
$ ("Selector"). removeAttr ()
Delete element attributes
11 style operations
$ ("Selector"). attr ()
Replace Style
$ ("Selector"). addClass ()
Append Style
$ ("Selector"). removeClass ()
Remove Style
$ ("Selector"). toggle ()
Repeated behavior Switching
Example:
The Code is as follows:
Script
$ X. toggle (function (){
// Code1
}, Function (){
// Code2
})
Script
Run code1 and code2 alternately.
$ ("Selector"). toggleClass ()
Controls repeated switching of styles, such as $ ("p"). toggleClass ("anotherClass ")
$ ("Selector"). hasClass ("anotherClass ")
Determine if selector contains anotherClass