The DOM is a tree-structured representation of an HTML document that JavaScript can read and modify. When the browser parses HTML, it creates a DOM tree where every element, attribute, and text node becomes a programmable object.

Learn JavaScript from these channels

  1. freeCodeCamp.org 12M subscribers · 7 videos on JavaScript in our index
  2. Fireship 4.3M subscribers · 7 videos on JavaScript in our index
  3. TutorialsPoint 3.7M subscribers · 5 videos on JavaScript in our index
  4. CS50 2.5M subscribers · 4 videos on JavaScript in our index
  5. Traversy Media 2.4M subscribers · 10 videos on JavaScript in our index

See all JavaScript channels →

How DOM Works

The DOM is what connects HTML to JavaScript. When you write document.getElementById('title'), you're accessing a DOM node. When React 'renders,' it's updating DOM nodes. When CSS selectors match elements, they're traversing the DOM tree.

Directly manipulating the DOM is slow. This is why React uses a Virtual DOM — a lightweight copy where changes are calculated first, then applied to the real DOM in a single batch. Svelte skips the Virtual DOM entirely and compiles to direct DOM updates.

Why Developers Use DOM

Every frontend developer works with the DOM. Whether through vanilla JavaScript (querySelector, addEventListener), jQuery (legacy), or modern frameworks (React, Vue, Svelte), you're always manipulating the DOM. Understanding it helps debug rendering issues and optimize performance.

Key Concepts

  • DOM Tree — The hierarchical structure of nodes — document → html → body → div → text
  • DOM Manipulation — Adding, removing, or changing elements with JavaScript — createElement, appendChild, innerHTML
  • Virtual DOM — A lightweight in-memory copy used by React to batch and minimize expensive real DOM updates
  • Event Bubbling — Events propagate from the target element up through parent nodes — click on a button bubbles to its container

Learn DOM — Top Videos

Frequently Asked Questions

What is the difference between DOM and HTML?

HTML is the text markup you write. The DOM is the live, in-memory tree structure the browser creates from that HTML. JavaScript modifies the DOM, not the HTML file.

Why is DOM manipulation slow?

Changing the DOM triggers layout recalculation (reflow) and repainting. Batch changes, use requestAnimationFrame, or use a framework with a Virtual DOM to minimize these expensive operations.