The HTML DOM (Document Object Model) represents a web page as a tree of objects, where every element, attribute and piece of text is a node; JavaScript uses this tree to read and change the page.
When the browser loads a page, it parses the HTML and builds the DOM tree. The document object is the root entry point.
For this HTML:
<html>
<head><title>My Page</title></head>
<body>
<h1>Hello</h1>
<a href="x.html">Link</a>
</body>
</html>
the tree is:
Document
└── html (root element)
├── head
│ └── title
│ └── "My Page" (text node)
└── body
├── h1
│ └── "Hello"
└── a [href="x.html"] (attribute node)
└── "Link"
Relationships: html is the parent of head and body; head and body are siblings; h1 is a child of body.
Node types: document node, element nodes, attribute nodes, text nodes, comment nodes.
What JavaScript can do with the DOM
let h = document.getElementById("title");
h.innerHTML = "New heading"; // change content
h.style.color = "blue"; // change style
let p = document.createElement("p"); // create element
document.body.appendChild(p); // add to tree
h.addEventListener("click", fn); // react to events
Common methods: getElementById(), getElementsByTagName(), getElementsByClassName(), querySelector(), createElement(), appendChild(), removeChild(). The DOM is what makes pages dynamic without reloading.