Document Object Model (DOM)
The Document Object Model represents a web document as a tree of objects that browser code can inspect, change, and observe.
Download Markdown (.md)Soroush’s Product Wiki · https://wiki.soroush.uk/topic/document-object-model/
01What it means
The Document Object Model (DOM) is a language-neutral programming interface for documents. A browser parses HTML into a tree of nodes such as documents, elements, text, and comments; scripts use DOM interfaces to read or change structure, content, attributes, and event behavior. The DOM is a web API, not part of the JavaScript language and not identical to the HTML source.[1][2]
The DOM is a web API and live node tree, not the original HTML source or part of the JavaScript language.
02Why it matters
Every dynamic browser interface depends on the relationship between source markup, the live DOM, rendering, and accessibility. DOM size and mutation patterns affect performance, while incorrect structure can damage interaction and assistive-technology output.
03When to use it
Use DOM concepts when implementing or debugging browser interfaces, events, component lifecycles, testing, or accessibility. Prefer native HTML behavior and targeted updates over rebuilding large subtrees when simpler markup can provide the result.
04How it works
- The browser parses a document and creates a hierarchy of node objects.
- DOM interfaces expose node properties, relationships, selectors, and mutation methods.
- Scripts attach event listeners or respond to browser-generated events.
- Mutations update the live document and may trigger style, layout, paint, or accessibility changes.
- Developer tools and observers reveal the resulting structure and changes.
05A practical example
A checkout script selects the shipping form, listens for a country change, and inserts the correct region field. The team verifies that the resulting DOM keeps the label association and focus order rather than merely looking correct.
06Where it breaks
The DOM does not describe pixels, network behavior, or the complete accessibility tree. Large trees and frequent layout-dependent mutations can be expensive, and a framework's virtual representation is not the browser DOM itself.
Common mistakes
- Treating the original HTML text and the current DOM as identical.
- Calling the DOM a feature of the JavaScript language.
- Replacing large subtrees for small changes without measuring the cost.
- Assuming a visually correct DOM is automatically semantic or accessible.
07Sources
- DOM StandardWHATWG · Living web standardDOM Standard
- Document Object Model (DOM)MDN Web Docs · Official technical documentationDocument Object Model (DOM)