Using this address, you can send a message to the intended recipient. The postal carrier simply uses the address you list and a road map to find the correct location. As long as there are no other Ernies at 123 Sesame Street in New York, you can feel safe that the addressee will receive your message.
If you need to send a message to someone else who happens to live at the same address as Ernie, however, all you have to do is change the name:
Although the addresses are very similar, each is still unique.
The DOM describes a path beginning with the window itself and moving down through the various objects on the Web page. Each element represents a node within the document, which is defined by an HTML tag, creating a tree-like structure in which each node object is a leaf in the tree. For example, Code 12.1 is broken down into nodes, as shown in Figure 12.2.
Code 12.1. A simple Web page with its node structure broken down, as shown in Figure 12.2.
Figure 12.2. The Web page node for Code 12.1 begins at the top with the window, moving down to each individual element on the page.
The following example is the path for the image called alice1:
This addresses an image object in the document in the current window called alice1.
If you needed to access an image called alice2, you would use this address instead:
window.document.images.alice1.src = "alice2.gif"
The W3C-Standard DOM
The W3C defines the Document Object Model as:
"… a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page" (w3.org/DOM/#what).
Clear enough? Basically, this definition says that the DOM is not dependent on any specific operating system or programming language, and allows scripting languages to access and change your Web page.
Earlier versions of both Netscape Navigator and Microsoft Internet Explorer included their own DOMs, which didn't work the same way. This was like having two different systems for addressing letters in the same country. The letters from one mail carrier could not be sent to addresses defined by the other mail carrier. This meant that Web designers had to create two versions of their code, and then determine which browser it was being viewed in to deliver the right address.
The good news is that the W3C published a standardized DOM, to which all modern browsers adhere. Score one for standards!
We will be using only the W3C standard DOM in this book, but for more details on the earlier Netscape and Internet Explorer DOMs, see the sidebar "The History of the DOM."
The code presented in this chapter uses the W3C standardized DOM, which will not work in Internet Explorer 4 or Netscape Navigator 4 (Table 12.2).