dagblog.
← Archive

Getting to know the DOM, part I


The DOM, or Document Object Model, has become a buzzword surrounded by
inaccuracies and myths. I’d like to show what it really is and what
the DOM specification lets us do.

What is the Document Object Model?

To understand why the
DOM specification was created, we need to explain what
the DOM is and what it represents.

At heart, the DOM is a set of interfaces, or
APIs, for working with valid HTML
and XML documents. It defines a document’s logical structure and provides the means to work
with it.

The DOM standardizes how you access and manipulate a document.
It lets programmers create, navigate and modify
a document in a consistent way. The specification is expressed as a set of programming
interfaces independent of any particular language.

The W3C is behind the DOM specification. The idea
of a single interface for working with documents regardless of language or platform was the main
reason for creating it. The individual interfaces were described in
IDL (Interface Definition Language).

This consistency, combined with the desire to unify the way we work with documents,
led to early DOM implementations in Java and especially
in web browsers. There it formed a standard
for working with HTML documents alongside the ECMAScript languages JavaScript and JScript.

Another factor behind the specification
was the desire to curb browsers’ proprietary DHTML extensions for working with documents.
For backward compatibility, some remnants of those proprietary extensions couldn’t be removed
completely. The idea that the DOM is a tool
exclusively for web browsers hasn’t gone away either.

The most important point is that the DOM provides
a transparent interface, independent of platform and language, for working in the same way
with XML and HTML documents.

Next we’ll look at a document as a tree of nodes, to see the logical structure that
makes it possible to define interfaces for working with it. Then we can look at how
the specification is split into modules. You can find it in the Document Object Model (DOM) Level 1 Specification (Second Edition),
which I’d like to keep using as the basis for this series.

Related articles

Medium version

Related articles

Related CZ Podcast episodes