In this article, I will introduce you to some suggestions on how to operate nodes in jQuery. If you need them, you can refer to the dynamic creation of Dom nodes.
In jQuery, $ (html string) is used to dynamically create Dom nodes and a jQuery object is returned. You can call the append method to add the created nodes to the Dom.
For example:
Var link = $ ("Baidu ");
$ ("P: first"). append (link );
Add a node element:
The Append method is used to Append an element (the last subnode) to the end of an element)
Prepend add an element (first subnode) at the beginning of the element)
After: add an element (add a sibling node) After the element)
Before: add an element Before the element (add a sibling node)
Child element. appendTo (parent element): append a child element to the end of the element.
Child element. prependTo (parent element): append a child element at the beginning of the element.
A. insertBefore (B) inserts A before B, equivalent to B. before ();
X. insertAfter (B) inserts X after Y, which is equivalent to Y. after (X );
Delete a node:
Empty (): clears all subnodes under this element.
Equivalent to: while (ele. firstChild) {ele. removeChild (ele. firstChild );}
Remove (selectot); stop; Delete the current element. The returned value is the deleted element. You can say that the deleted node is placed under another node and has a moving effect, for example:
Var lis = $ ("# ulSite li"). remove ();
$ ("# UlSite2"). append (lis );
Clone (): Clone a node, supporting a replication node. Do not copy a node.
Clone (true): Clone node with event
Node replacement:
$ ("Br"). replaceWith ("
");
$ ("Br"). replaceAll ("
");
Package Node
The Wrap () method is used to Wrap all elements one by one with the specified label.
$ ("B"). wrap (""); show all bold characters in red
WrapInner ();