The following small series will bring you an article on jquery and DOM node operation methods and attribute records. I think this is quite good. I will share it with you and give you a reference.
I found a list of jquery operation node methods on the Internet. As follows:
| Method |
Source package set/string |
Target package Group |
Feature description |
| A. append (B) |
B |
A |
If the target packaging set matches only one element, the source (including all elements matching the same source packaging set) will be moved to the target location. If the target packaging set contains multiple elements, the source will be retained in the original location, but an identical copy will be copied to the target location at the same time. Therefore, if the target matches only one element, the source will be deleted after the preceding method is used. |
| B. appendTo () |
| A. prepend (B) |
| B. prependTo () |
| A. before (B) |
| B. insertBefore () |
| A. after (B) |
| B. insertAfter () |
Example: in the preceding table,. append (B) indicates adding B to the existing content of all elements matching A. Therefore, B is the source and A is the target packaging set.
To sum up, the two nodes are changed to sibling nodes after the preceding method is used.
The following is a summary of DOM operation nodes:
(1) appendChild method, used to add a node to the end of the childNodes list
// Add newNode to the end of the childNodes list of someNode
Var returnedNode = someNode. appendChild (newNode );
// Change the first child node of someNode to the last child node
Var returnedNode = someNode. appendChild (someNode. firstChild );
(2) insertBefore method. You can place the node in a specific position in the childNodes list.
// Insert and become the last subnode
ReturnedNode = someNode. insertBefore (newNode, null); // the same effect as appendChild
// Insert and become the first subnode
ReturnedNode = someNode. insertBefor (newNode, someNode. firstChild );
(3) The replaceChild method is used to replace a subnode. Two parameters are accepted: the subnode to be inserted and the subnode to be replaced. The child node to be replaced will be removed from the document tree and occupied by the child node to be inserted
// Replace the first subnode
ReturnedNode = someNode. replaceChild (newNode, someNode. firstChild );
(4) The removeChild method is used to remove sub-nodes.
// Remove the first subnode
Var formerFirstChild = someNode. removeChild (someNode. firstChild );
To sum up, the above methods are used by the parent node to operate the child node.
Provides the relationship between parent and child, and brothers.
All of the above content about jquery and DOM node operation methods and attribute record is shared by Alibaba Cloud. I hope you can give us a reference and support for others.