This article mainly introduces the basic tutorials for JavaScript operations on HTMLDOM nodes, including operations such as creating, modifying, and deleting nodes. It also mentions appendChild () and insertBefore () when inserting a node, you need to pay attention to this issue. For more information, see the DOM. This allows you to use JavaScript to obtain, create, modify, or delete a node.
NOTE: The elements in the example below are all element nodes.
Get Node
Parent-child relationship
element.parentNodeelement.firstChild/element.lastChildelement.childNodes/element.children
Sibling relationship
element.previousSibling/element.nextSiblingelement.previousElementSibling/element.nextElementSibling
Obtaining nodes through the direct relationship between nodes greatly reduces code Maintainability (the changes in the relationship between nodes directly affect the nodes to be obtained), and the interface can effectively solve this problem.
Obtaining nodes through the direct relationship between nodes greatly reduces code Maintainability (the changes in the relationship between nodes directly affect the nodes to be obtained), and the interface can effectively solve this problem.
ELEMENT_NODE & TEXT_NODE
- First
- Second
- Third
- Fourth
Hello