Home >Web Front-end >JS Tutorial >Detailed explanation of node operation examples of DOM methods
document.createElement(tagName)
Create an element in the form of a tag name
parentNode.appendChild(childNode)
Add a child node to a node, note that it is added at the end
parentNode .insertBefore(childNode1,childNode2)
Insert a node in front of the specified child node of a node
As above: childNode1 is inserted in front of childNode2;
parentNode.removeChild(childNodes)
From a node Delete the specified child node.
parentNode.replaceChild(node,childNode)
node is used to replace the node, childNodes is the child node to be replaced
Both parameters must be written.
node.cloneNode(boolean)
Clone a node
true: Clone the element and the descendant nodes contained by the element
flase: Clone the element but not include the descendant nodes of the element
node. parentNode parent node
node.offsetParent locates the parent
node.children child node
node.perviousElementSibling previous sibling node
node.nextElementSibling next sibling node
node.firstElementChild (get node First child node)
node.lastElementChild (get the last child node in node)
The above is the detailed content of Detailed explanation of node operation examples of DOM methods. For more information, please follow other related articles on the PHP Chinese website!