Chapter 13. The Document Object Model

In conventional applications, the operating system provides user interface elements and behaviors that enable developers to provide a rich experience for the user. Developing such applications is convenient, as the entire application is typically written in one language. The developer needs to know only one language to write code to interface with a data store (such as a database), code to process that data, code to display that data to the user, and code to interact with the user.

Web developers don't have it that easy. The data store interaction and processing are written in one language (like PHP, Python, or C#), and the user interface is typically a combination of HTML, CSS, and JavaScript. HTML is used for basic output/input for the user, which is a rather static and boring experience. CSS can spice up the application a little, but it isn't designed to do much more than determine how the browser renders the elements. So, to create a rich interactive experience, developers must turn to JavaScript.

But JavaScript is only part of the equation. There has to be an interface that enables a JavaScript developer to interact with a web page while it's loaded in the browser; such an interface exists, and it's called the Document Object Model (DOM).

WHAT IS THE DOM?

The DOM is a browser-independent Application Programming Interface (API) — a set of objects, properties, and methods that defines how HTML documents are structured, accessed, and manipulated ...

Get JavaScript® 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.