Chapter 12. Dynamic HTML and the W3C Document Object Model

JavaScript's primary role in web development is to interact with the user, to add some kind of behavior to your web page. You've seen this in previous chapters, especially Chapter 7 and Chapter 8 when you were scripting forms, frames, and windows. User interaction doesn't stop there, though. In fact, JavaScript gives you the ability to completely change all aspects of a web page after it's loaded in the browser, a technique called Dynamic HTML (DHTML). What gives JavaScript this power over a web page is the Document Object Model (DOM), a tree-like representation of the web page.

The DOM is one of the most misunderstood standards set forth by the World Wide Web Consortium (W3C), a body of developers who recommend standards for browser makers and web developers to follow. The DOM gives developers a way of representing everything on a web page so that it is accessible via a common set of properties and methods in JavaScript. By everything, I mean everything. You can literally change anything on the page: the graphics, tables, forms, and even text itself by altering a relevant DOM property with JavaScript.

The DOM should not be confused with the Browser Object Model (BOM) that was introduced in Chapter 6. You'll see the differences between the two in detail shortly. For now, though, think of the BOM as a browser-dependent representation of every feature of the browser, from the browser buttons, URL address line, and title bar ...

Get Beginning JavaScript®, Fourth Edition 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.