15.1. Interfaces

The HTML Document Object Model is an application programming interface (API) that defines the structure of an HTML document in the browser. In addition, it defines how that document can be accessed and manipulated through the use of JavaScript, sometimes embedded within the very same HTML document that is being manipulated.

This sounds a little scary doesn't it? The idea that a JavaScript routine could essentially modify the very fabric of its own universe can be terrifying. Just one oops, and it is overit modified itself right out of existence. For all intents and purposes, as far as the browser was concerned, it would have never existed. Fortunately, this takes a little work to accomplish, and only the JavaScript function and possibly the associated page would cease to exist. Believe me, if this wasn't the case, I would have winked out long ago.

Table 15-1 shows the various HTML Document Object Model interfaces available through JavaScript. I would like to point out that the majority of these interfaces correspond to actual HTML elements. Yes, name an HTML element, and there is a corresponding interface; remember, though, that just because an interface exists for a deprecated element, you don't have to use it. It is still deprecated.

15.1.1. Window

Although it's not officially part of the HTML Document Object Model, the window object is the big kahuna, the big cheese, or, in web development terms, top of the hierarchy. Many web developers don't realize it, but all HTML documents are actually children of the window object. This means that it is as valid to code window.document as it is to code document. You will probably see only the latter as opposed to the former, but I think it's a good idea to point out the possibility of the former, if only to avoid those Homer Simpson moments: Doh!