Chapter 10. The Document Object Model

In Chapter 9 we saw JavaScript objects that represented the form and input tags from an HTML document. Such objects are part of a structure called the Document Object Model (DOM). Every tag in the document is represented by an object in this model and can be looked up and interacted with.

DOM Elements

HTML documents have a hierarchical structure. Each element (tag) except the top <html> element is contained in another element, called its parent. This element can in turn contain child elements. You can visualize this as a kind of family tree. If we have a simple document like this:

<html> <head> <title>Alchemy for beginners</title> <script type="text/javascript" src="js/base.js"></script> </head> <body> <h1>Chapter ...

Get Eloquent JavaScript 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.