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 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.