1. Attribute operation 1) Search for the attribute node: the attr () method to obtain the attribute value. Its parameters can be one or more. For example, attr ("title ") // obtain the attribute value attr ("title", "aaaaaaaaa") // change the attribute value to aaaaaaaaa; 2) removeAttr () method to delete the element attribute;
2. Create a node: var $ lia = $ ("<li title =" aa "> aaaaa </li> ")
3. Insert node: append () directly; appendTo () append to Example. appendTo (B) means that A is appended to B, and the order is the opposite of append (); prepend () is inserted to the front of the element (opposite to after ();. prependTo (B) describes how A is inserted before B (opposite to insertAfter );
4. Method for deleting a node: remove (). After deletion, you can continue to use these elements. For example, $ aa =$ ("ul li: eq (1)"); $ aa. remove (); $ ("ul "). append ("$ aa"); the empty () method is to clear the node; for example
<Html>
<Head>
<Script type = "text/javascript" src = "jquery-1.3.2.min.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Var $ bb = $ ("ul li: eq (1 )");
$ Bb. remove ();
})
</Script>
</Head>
<Body>
<Ul>
<Li> aa </li>
<Li> bb </li>
<Li> cc </li>
</Ul>
</Body>
</Html>
The output result is. aa... bb. If it is the remove () method, the output result is. aa. bb;
5. Copy node $ ("aa"). clone (true) // If the parameter true is not added, the copied element does not have the behavior of the parent element;
6. Replace nodes: replaceWith () and replaceAll () methods (the two methods work in the same way, but the order of use is reversed). For example: replace <p> aaaaaaaaaaaa </p> with <a href = ""> bbbbbbbbbbbbbbb </a>. The Code is as follows: $ ("p "). replaceWith ("<a href =" "> bbbbbbbbbbbbbbbbb </a>"); or $ ("<a href =" "> bbbbbbbbbbbbbbbbbbbbb </a> "). replaceAll ("p ");
7. Method of package nodes: 1) wrap () indicates that all matching elements are packaged separately;
2) The wrapAll () method is to wrap all matching elements with one element;
3) wrapInner () means to wrap the child content (including text nodes) of all matched elements with structured tags;
8. style operation: 1) Replace the style $ ("ul"). attr ("class", "aa ");
2) append style $ ("ul"). addClass ("aa ");
3) Remove the style $ ("ul"). removeClass ("aa ");
4) The toggleClass () method controls repeated switching of styles. If yes, It is deleted. If no, it is added;
5) determine whether a style exists $ ("p"). is (". another ");