HTML DOM Nodes
In the HTML DOM, everything is a node. The DOM is HTML viewed as a tree of nodes.
DOM Nodes
DOM Nodes
According to the W3C HTML DOM standard, everything in an HTML document is a node:
- The entire document is a document node
- Every HTML element is an element node
- The text inside an HTML element is a text node
- Every HTML attribute is an attribute node
- A comment is a comment node
HTML DOM Node Tree
The HTML DOM views an HTML document as a tree structure. This structure is called anode tree:
HTML DOM Tree Example
Node Parents, Children, and Siblings
Nodes in a node tree have hierarchical relationships with each other.
We commonly useparent, childandsiblingand other terms to describe these relationships. A parent node has child nodes. Child nodes at the same level are called siblings (brothers or sisters).
- In a node tree, the top node is called the root.
- Every node has a parent node, except the root (which has no parent node).
- A node can have any number of child nodes.
- Siblings are nodes that have the same parent node.
The image below shows a part of the node tree, as well as the relationships between nodes:

See the HTML snippet below:
From the HTML above:
- node has no parent node; it is the root node
- and 's parent node is Node
- The parent node of the text node "Hello world!" is
Node
And:
- The node has two child nodes: and
- The node has two child nodes: The difference between
node The node also has a child node: the text node "DOM tutorial" and
The node is a sibling node, and is also
child node
and:
- the element is the first child node of the element
- the element is the last child node of the element
the element is the first child node of the element
the element is
the last child node of the element
Warning!
A common mistake in DOM processing is expecting an element node to contain text.
In this example: