All nodes
In the HTML DOM (Document Object model), nodes mainly include (numbers in parentheses denote node types): Elements (1), Attributes (2), text (3, where line breaks are also a text node), comments (8),文档(9)
。
The main application of these methods is to increase, delete, change and investigate.
1, increase, in the previous essay has introduced the two methods in detail.
2, delete, that is element.removechild () remove the child node from the element.
Syntax: Node.removechild (node)
Returns the node that was deleted as a node object, or null if it does not exist.
Step: (1) Get parent node (2) Get the node you want to delete (3) Delete node
Parent.removechild (child);
3, change, that is, Element.replacechild () Replace the child nodes in the element.
语法:node.replaceChild(newnode,oldnode)
新节点可以是文档中某个已存在的节点,或者您也可创建新的节点。
旧节点会被删除
步骤:(1)创建一个新节点或选择已有节点(
2)获取父节点(
3)获取想要被替换的节点
(4)替换节点
parent.replaceChild(para,child);
4, check, query node, there are many methods, such as:
Element.firstchild returns the first child of the element.
Element.firstchild returns the first child of the element.
Element.nextsibling returns the next node at the same node tree level.
Element.nextsibling returns the next node at the same node tree level.
Element.parentnode returns the parent node of the element.
Element.parentnode returns the parent node of the element.
Element.parentnode returns the parent node of the element.
HTML DOM Node