HTML DOM Nodes
The entire document is a document node
Each HTML element is an element node
Text inside an HTML element is a text node
Each HTML attribute is an attribute node
Comments are comment nodes
HTML DOM node tree
HTML DOM Tree Example
Node parent, child and sibling
In a node tree, the top node is called the root.
Every node has a parent, except the root (which has no parent).
A node can have any number of child nodes.
Siblings are nodes that have the same parent.
<html> <head> <meta charset="utf-8"> <title> DOM tutorial </title> </head> <body> <h1>DOM Course 1</h1> <p>Hello world!</p> </body> </html>
The <html> node has no parent; it is the root node
The parent node of <head> and <body> is the <html> node
The parent of the text node "Hello world!" is the <p> node
The <html> node has two children: <head> and <body>
The <head> node has two children: <meta> and <title> nodes
The <title> node also has a child node: the text node "DOM Tutorial"
The <h1> and <p> nodes are siblings and children of <body>
The <head> element is the first child of the <html> element
The <body> element is the last child of the <html> element
The <h1> element is the first child of the <body> element
The <p> element is the last child of the <body> element