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 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 of 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> ...
Get Coding with JavaScript For Dummies 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.