Dom is about how to get, modify, add or remove HTML elements of the standard, below for everyone to introduce the next HTML DOM node operation, interested friends can refer to the followingThe HTML DOM is the standard for how to get, modify, add, or delete HTML elements. In the HTML DOM, all things are nodes. The DOM is the HTML that is considered a node tree.
All content in an HTML document is a node, based on the HTML DOM standard of the paper:
The entire document is a document node
Each HTML element is an element node
Text within an HTML element is a text node
Each HTML attribute is an attribute node
Comment is a comment node
The HTML DOM sees an HTML document as a tree structure. This structure is called a node tree:
HTML DOM Tree Instance
Through the HTML DOM, all nodes in the tree can be accessed through JavaScript. All HTML elements (nodes) can be modified, or nodes can be created or deleted.
All HTML elements are defined as objects, while programming interfaces are object methods and object properties.
One: Gets the element node method:
1.var node = document.getElementById ("NodeId");
2.var nodelist = Document.getelementsbyclassname ("Nodeclassname");
3.var nodelist = document.getElementsByTagName ("Nodetagname");
Two: Get to the element node after we can do the operation on him: 1. operate on itself. 2. Operation of the child node. 3. Operation of the sibling node. 4. Actions on the parent node
2.1. Delete itself: node.parentNode.removeChild (node);
2.2. Determine if there are child nodes: var Boolean = Node.haschildnodes ();
Get a list of child nodes: var childlist = node.childnodes;
Get node element type: var NodeType = Node.nodetype; var nodename = Node.nodename;
Deletes a child node. Node.removechild (Childnode);
Insert a child node at the end of the child node: Node.appendchild (Childnode);
A child node is not inserted in the child node: Node.insertbefore (Childnode);
Replace the B node with A node: Node.replacechild (A, A, A);
2.3.node.nextsibling get adjacent next sibling node
Node.previoussibling gets the adjacent previous sibling node
2.4. Get parent Node Node.parentnode original address:
HTML DOM node
(reproduced) HTML DOM node operations (GET/modify/Add or delete)