I. node operations
1. Find nodes:
Var $ var_1 = $ ("htmltype"); // obtain all htmltype nodes.
For example, var $ ul_1 = $ ("ul ");
2. Create and append a node:
Var $ var_1 = $ ("
$ ("Htmltype2"). append ($ var_1); // inserts a node into all htmltype2 nodes.
Example: var $ li_1 = $ ("<li title =" title1 "> banana </li> ");
$ ("Ul"). append ($ li_1 );
The following insert methods are available:
- Append () append B to A (all A elements, similar to the following)
- AppendTo (): append A to B.
- Prepend () before appending B to the content inside
- PrependTo () before appending A to B
- After () append B after
- InsertAfter () append B before
- Before () append B before
- InsertBefore () append B after
Example: $ ("ul"). append ("<li> Hello </li>"); // append li inside ul
$ ("<Li> Hello </li>"). appendTo ("ul"); // append the li
3. delete a node
- Remove () delete this element
- Empty () clears nodes, including child nodes
Example: $ ("ul li: eq [1]"). remove (); // obtain the second li In ul and delete it
$ ("Ul li"). remove ("li [title =" pineapple "]"); // Delete the element of the li element attribute title = "pineapple" In ul
4. Copy a node
- Clone (); // copy the current node
Example: $ ("ul li: eq [1]"). clone (). appenTo ("ul"); // copy and append it to ul. Only copying is not displayed.
5. Replace nodes
- ReplaceWith (); // replace B with all
- ReplaceAll (); // replace A with all B
6. Package nodes
- WarpAll (); // wrap A with B
- WarpInner (); // wrap the content of A with B
Ii. Attribute operations
1. Get and set attributes
Var $ var_1 = $ ("p"); // obtain the node P
Var $ p_1 = $ var_1.attr ("title"); // obtain the title attribute of node P.
Var $ p_2 = $ var_1.attr ("title", "hello"); // set the title attribute of node P to "hello"
2. Delete attributes
$ ("P"). removeAttr ("title"); // Delete the Title attribute of node P
3. style operations
1. Get and set styles
Var $ var_class = $ ("p"). attr ("class"); // obtain the class attribute of node P.
$ ("P"). attr ("class", "class1"); set the class attribute of node P to the style sheet class class1
2. append a style
- AddClass () Add A style to
Example: $ ("p"). addClass ("another"); Add the style sheet class another class to P
3. Remove a style
- RemoveClass () Remove Class
4. Switch the style
- ToggleClass () switches the clss attribute class to a new class.
5. Determine whether a style exists
Iv. Content operations
- Html () This method obtains the content of the html element, such as var var1 =1 ("p" ).html (); // obtains the content of the P element.
- Text () gets or sets the content of an html element.
- Val () is used to obtain the Value of an element.
- Children () obtains all child nodes of the html element.
- Next () The peer node next to the html Element
- Prev () gets the peer node next to the html Element
- Siblings () obtains peer nodes adjacent to html elementsBytes
5. CSS-DOM Technology
- Css ("attribute", "value") sets the value of an attribute of element css, such as: $ ("p" ).css ("color", "red "); // set the css attribute of P {color: red ;}