SoFunction
Updated on 2025-03-03

Basic DOM node operation

1. Get element nodes

getElementById(): Gets the element with the specified unique id.

getElementByTagName(): Gets the element array of specified element tag names.

getElementByName(): Gets an array of elements with the specified attribute name.

2. Children nodes

: Returns the child node array of this element. Note: Line breaks are used as text nodes in the browser and need to be filtered

: The first child node of this element.

: The last child node of the element.

3. Parent node

4. Brotherly nodes

: Returns the previous node in the same tree hierarchy, if not, null

: Returns the next node in the same tree hierarchy, if not, null

5. Create a node

createElement() Create node by the specified tag name

6. Replication node

clonedNode = (boolean) Pass in a boolean value, true means that all child nodes under the node are copied

7. Join the node

(childNode) Add a new node to the end of a child node

(newNode, targetNode) Before adding newNode to targNode

8. Remove the target node

(childNode)

9. Replace the target node

(newNode, targetNode) Replace targetNode with newNode

The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!