3 THE DOCUMENT OBJECT MODEL

What this chapter covers:

  • The concept of nodes
  • Four very handy DOM methods: getElementById, getElementsByTagName, getAttribute, and setAttribute

It's time to meet the DOM. I'd like to introduce you to the Document Object Model and show you the world through its eyes.

D is for document

The Document Object Model can't work without a document. When you create a web page and load it in a web browser, the DOM stirs into life. It takes the document that you have written and turns it into an object.

In normal everyday English, the word "object" isn't very descriptive. It simply means thing. In programming languages, on the other hand, "object" has a very specific meaning.

Objects of desire

At the end of the last chapter, ...

Get DOM Scripting: Web Design with JavaScript and the Document Object Model 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.