You are previewing Eloquent JavaScript.

Eloquent JavaScript

Cover of Eloquent JavaScript by Marijn Haverbeke Published by No Starch Press
O'Reilly logo

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

The best content for your career. Discover unlimited learning on demand for around $1/day.