Chapter 10
Manipulating Documents with the DOM
IN THIS CHAPTER
Getting to know the DOM (Document Object Model)
Working with nodes
Moving around the tree
Selecting elements
“No object is mysterious. The mystery is your eye.”
— ELISABETH BOWEN
Understanding the DOM is key to being able to manipulate the text or HTML in a web page. Using the DOM, you can create animations, update data without refreshing web pages, move objects around in a browser, and much more!
Understanding the DOM
The Document Object Model (DOM) is the interface for JavaScript to talk to and work with HTML documents inside of browser windows. The DOM can be visualized as an inverted tree, with each part of the HTML document branching off its containing part.
Listing 10-1 is the markup for a web page. The DOM representation is shown in Figure 10-1.
LISTING 10-1: An HTML Document
<html><head> <title>Bob's Appliances</title></head><body> <header> <img src="logo.gif" width="100" height="100" alt="Site Logo"> </header> <div> <h1>Welcome to Bob's</h1> <p>The home of quality appliances</p> </div> <footer> copyright ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access