Skip to content
IT glossary
FrontendUpdated December 3, 2026

DOM

The Document Object Model (DOM) represents a web page as a tree of objects. It lets code find and change parts of the page and respond to actions such as clicks.

Also known as: Document Object Model

From HTML to a tree

HTML is the text the browser parses. The Document Object Model (DOM) is the tree the browser builds from it, along with the standard interfaces code uses to work with that tree. In <li>Read <em>chapter one</em></li>, the li element has two children: a text node containing Read and an em element. The words chapter one are a text node inside em. This is why childNodes can include text and comments, while children contains only elements.

Finding and changing elements

In a browser, document gives JavaScript access to the current document. Use document.querySelector() to find the first element that matches a CSS selector. It returns null if there is no match, which can happen if the script runs before the browser has parsed that part of the page. Loading an external classic script with defer lets the browser finish parsing the HTML before running the script.

Finding or creating an element isn't the same as inserting one. For example, document.createElement('li') returns a new element that is not yet part of the page. To make it a child of an existing list, call the list's append() method.

Example: add a list item

Suppose the page already contains <ul id="tasks"></ul> and the script runs after that element has been parsed:

const list = document.querySelector('#tasks');
const item = document.createElement('li');
item.textContent = 'Review the pull request';
list.append(item);

The item now belongs to the list in the browser's DOM; the original HTML file hasn't changed. textContent inserts plain text, so if the label came from a form and included angle brackets, the browser would display them as text rather than parse them as tags.

What the DOM is not

The DOM describes document structure, not the pixels on the screen. An element styled with display: none is still in the DOM and can still be found with a selector. The DOM is also distinct from a virtual DOM: some UI libraries keep a separate representation of the interface to decide which updates to apply to the browser's DOM. When debugging, inspect the live tree in the Elements panel rather than relying on View Source, which won't show nodes added by JavaScript.

How it comes up in interviews

A common exercise is to make every row in a list clickable, including rows added after the page loads. One option is event delegation: put a single listener on the list and use the event's target to identify the row. This works because click events bubble from the clicked element to its ancestors. Be ready to explain what happens when the user clicks a nested icon rather than the row itself.