DOM explorer
A small page and its DOM tree: click a node to see how JavaScript finds it, and change its text.
The browser turns your HTML into a tree of nodes called the DOM. JavaScript can find a node with document.querySelector and change it, for example with textContent.
The HTML file stays the same when you change the DOM; only the page in the browser changes. Click the nodes of the tree and watch the JavaScript line change.
Things to try
- Click <h1>, then change its text. What happens to the page and to the tree?
- Click <p> and <button>. How does the querySelector line change?
- Click <body>. Why can you not type text for it?
- Change the text of <title>. Where do you see it?