Datasheet

Chapter 1: What Is JavaScript?
7
The Document Object Model ( DOM )
The Document Object Model (DOM) is an application programming interface (API) for XML that was
extended for use in HTML. The DOM maps out an entire page as a hierarchy of nodes. Each part of
an HTML or XML page is a type of a node containing different kinds of data. Consider the following
HTML page:
< html >
< head >
< title > Sample Page < /title >
< /head >
< body >
< p > Hello World! < /p >
< /body >
< /html >
This code can be diagrammed into a hierarchy of nodes using the DOM (see Figure 1 - 3 ).
Sample Page
html
head
title
body
p
Hello World!
Figure 1 - 3
By creating a tree to represent a document, the DOM allows developers an unprecedented level of
control over its content and structure. Nodes can be removed, added, replaced, and modified easily by
using the DOM API.
Why the DOM Is Necessary
With Internet Explorer 4 and Netscape Navigator 4 each supporting different forms of Dynamic HTML
(DHTML), developers for the first time could alter the appearance and content of a web page without
reloading it. This represented a tremendous step forward in web technology, but also a huge problem.
Netscape and Microsoft went separate ways in developing DHTML, thus ending the period when
developers could write a single HTML page that could be accessed by any web browser.
c01.indd 7c01.indd 7 12/8/08 11:21:51 AM12/8/08 11:21:51 AM