DOM

What is it?

The Document Object Model (DOM) is a programming interface that represents an HTML document as a tree structure where each element, attribute, and piece of text becomes a node. JavaScript can interact with this tree to dynamically read, modify, add, or delete elements on a webpage, enabling interactive and dynamic user experiences without reloading the page.

Practical example

To change the text of a heading when a user clicks a button, you first select the element using document.getElementById or querySelector, then modify its content with element.textContent. You can also change styling with element.style properties, add CSS classes with classList.add, or create entirely new elements using createElement and appendChild methods.

Test your knowledge

What does the DOM represent?

Ask Lex
Lex knows the context of this term and can give targeted explanations, examples, and extra context.
Tip: Lex replies briefly in the widget. For more detail, go to full screen mode.

Quick links