Home >Web Front-end >JS Tutorial >Detailed explanation of node operation examples of DOM methods

Detailed explanation of node operation examples of DOM methods

零下一度
零下一度Original
2017-06-26 09:15:251232browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn