In the HTML DOM, everything is a node. DOM is HTML viewed as a tree of nodes.
HTML DOM node syntax
According to W3C's HTML DOM standard, all content in an HTML document is a node:
The entire document is a document node
Each HTML element is an element node
The text within the HTML element is a text node
Each HTML attribute is an attribute node
Comments are comment nodes
HTML DOM node example
<html> <head> <meta charset="utf-8"> <title>DOM 教程</title> </head> <body> <h1>DOM 课程1</h1> <p>Hello world!</p> </body> </html>
From the HTML above: The
<html> node has no parent; it is the root node
<head> and <body>'s parent is < html> node
The parent node of the text node "Hello world!" is the<p> node
and:
<html> node has two child nodes:< The ;head> and <body>
<head> nodes have two child nodes: the <meta> and <title> nodes
<title> node also has one child node : Text node "DOM Tutorial"
<h1> and <p> nodes are sibling nodes and are also child nodes of <body>
And:
The <head> element is the first child node of the <html> element
<body> The element is the last child node of the <html> element
<h1> The element is< The ;body> element's first child node
<p> element is the last child node of the <body> element