Easy Tutorial
❮ Htmldom Properties Htmldom Modify ❯

HTML DOM Nodes


In the HTML DOM, everything is a node. The DOM is considered a tree of nodes from the HTML.


DOM Nodes

According to the W3C HTML DOM standard, everything in an HTML document is a node:


HTML DOM Tree of Nodes

The HTML DOM views an HTML document as a tree structure. This structure is called the tree of nodes:

HTML DOM Tree Example


Node Parents, Children, and Siblings

Nodes in the tree of nodes have hierarchical relationships.

We use terms like parent, child, and sibling to describe these relationships. A parent node has child nodes. Child nodes at the same level are called siblings (brothers or sisters).

The following image shows part of the node tree and the relationships between the nodes:

Consider the following HTML snippet:

<html>
  <head>
    <meta charset="utf-8">
    <title>DOM Tutorial</title>
  </head>
  <body>
    <h1>DOM Lesson 1</h1>
    <p>Hello world!</p>
  </body>
</html>

From the above HTML:

And:

Also:


Warning!

A common mistake in DOM processing is expecting element nodes to contain text.

In this example: <title>DOM Tutorial</title>, the element node <title> contains a text node with the value "DOM Tutorial".

You can access the value of the text node through the innerHTML property of the node.

You will learn more about the innerHTML property in later chapters.

❮ Htmldom Properties Htmldom Modify ❯