Chapter 3. The Document Object Model

What this chapter covers:

  • The concept of nodes

  • Five very handy DOM methods: getElementById, getElementsByTagName, getElementsByClassName, getAttribute, and setAttribute

It's time to meet the DOM. This chapter introduces you to the DOM and shows you the world through its eyes.

D is for document

The DOM can't work without a document. When you create a web page and load it in a web browser, the DOM comes to 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 previous chapter, you saw some ...

Get DOM Scripting: Web Design with JavaScript and the Document Object Model, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.