The DOM (Document Object model) is an API for HTML and XML documents.
The DOM can portray any HTML or XML document as a tree structure consisting of a multi-level node, with a specific node as the root node. The nodes are divided into 12 different types, each representing different information and/or tags in the document. These types inherit from a base type.
Take the following example:
<HTML> <!--document element, a child node of a document node, is the outermost element of the document. There is only one document element per document. - <Head> <title>My article</title> </Head> <Body> <P>Hello World</P> </Body></HTML>
The document node is the root node of each document. All other elements in the document are contained within the document element.
1. Node type
All node types in JavaScript inherit from node type.
Each node has a NodeType property (Somenode.nodetype), the type of the surface node. There are 12 numeric constants defined in the node type, and any node type must be one of the following:
To understand the details of a node, you can use NodeName and nodevalue. For an element node, NodeName always holds the label name of the element, while the value of NodeValue is always null.
node Relationship :
Operation Node :
AppendChild (NewNode)--Adds a node to the end of the ChildNodes list, returning the new node. If the node passed into AppendChild () is already part of the document, the result is that the node is transferred from its original location to the new location.
InsertBefore (the node to be inserted as the node of the reference)-place the node in a specific position in the ChildNodes list, returning the inserted node. When a node is inserted, the inserted node becomes the previous sibling node (previoussibling) of the reference node.
ReplaceChild (node to be inserted, nodes to replace)--returns the node to be replaced and removes it from the document tree.
JS DOM node type