Unit 7 · JavaScript

7.7The DOM (Document Object Model) Tree

When a browser loads an HTML page it builds a tree of objects in memory called the DOM. JavaScript can read and change this tree, and the page updates instantly.

HTML
<html>
  <body>
    <h1 id='title'>Hello</h1>
    <ul>
      <li>One</li>
      <li>Two</li>
    </ul>
  </body>
</html>

The tree for this page:

documenthtmlbodyh1#titleul'Hello'lili'One''Two'parent of h1 and ul →children of ulsiblingselement nodetext node
The DOM tree: element nodes (blue) and text nodes (green); document is the root

Try it: Open any website, press F12, open the Elements tab and expand the tree. Then in the Console type document.body.children and document.title.