liveBook · Manning

Document Object Model

As explained in D3.js in Action, Third Edition

The Document Object Model is a programming interface that represents a web document as a structured tree of objects and elements.

The Document Object Model (DOM) is the browser’s programming interface for a web document. It represents HTML as a tree of nested nodes: parents contain children, and related elements can be siblings. The visible page comes from the elements inside the body. section 1.2.1

Each DOM element combines styles, attributes, and properties. Styles control appearance, attributes include identifiers such as classes and IDs, and properties represent changing state such as whether a checkbox is checked. In SVG, attributes also define shape position, size, and proportions. section 1.2.1

A small document tree

An HTML document can contain html as the root, head and body as children, and h1, div, and p elements nested inside body. For SVG, the DOM order also controls drawing order: later elements are painted on top of earlier ones. section 1.2.1

D3 uses the DOM as the working surface for visualizations. d3.select() finds the first matching element, d3.selectAll() finds every match, append() adds children, and attr() and style() modify presentation. Their selectors use familiar CSS tag, class, and ID syntax. section 2.0 section 2.7

When a frontend framework also controls the DOM, unrestricted D3 manipulation can cause conflicts. D3 can control an isolated region, act only as a utility library for calculations, or share control selectively through a hybrid approach. section 8.1 section 8.6

How D3.js in Action, Third Edition covers it

How deep it goes
Explains tree structure, element state, SVG painting order, and core D3 operations, then defers framework integration trade-offs to strategies.
Examples
Uses a nested HTML file, SVG shapes, CSS-style selectors, and framework-built scatterplots to illustrate document structure and control.
What it assumes
Builds from basic HTML nesting and CSS selector syntax while introducing DOM terminology and element state distinctions.
What you can do after
Apply D3 selections, append elements, and modify attributes and styles to build HTML or SVG visualizations.
How it connects
Connects HTML, CSS selectors, SVG, D3, JavaScript frameworks, React, and Svelte.

Also explained in

Compare how 8 books explain Document Object Model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.