The discussion of the DOM really does require that you are extremely comfortable with (X)HTML and CSS. Readers who are not are encouraged to review these topics, for example, in the companion book HTML & XHTML: The Complete Reference 4th Edition by Thomas Powell (Osborne/ McGraw-Hill, 2003).
In order to straighten out the object model mess presented in the last chapter, the W3C has defined three levels of the DOM, listed next.
DOM Level 1 Provides the ability to manipulate all elements in a document through a common set of functions. In DOM Level 1, all elements are exposed and parts of the page can be read and written to at all times. The Level 1 DOM provides capabilities similar to Internet Explorer’s document.all collection, except that it is cross-browser–compatible and standardized.
DOM Level 2 Provides further access to page elements primarily related to XML and focuses on combining DOM Level 0 and Level 1 while adding support for style sheet access and manipulation. This form of the DOM also adds an advanced event model and the lesser known extensions such as traversal and range operations. Unfortunately, beyond style sheet access, many DOM Level 2 features are not supported in common Web browsers including those that claim fantastic standards support.
At the time of this book’s writing, the DOM Level 3 is still in development. This version of the DOM will improve support for XML including adding support for XPath, extend Level 2’s event model (primarily to support keyboard and device events), and add features to allow content to be exchanged between files (including a load and save feature to exchange documents).
Another way of looking at the DOM as defined by the W3C is by grouping the pieces of the DOM concept into the following five categories:
DOM Core Specifies a generic model for viewing and manipulating a marked up document as a tree structure.
DOM CSS Provides the interfaces necessary to manipulate CSS rules programmatically.
DOM Events Adds event handling to the DOM. These events range from familiar user interface events such as mouse clicks to DOM-specific events that fire when actions occur that modify parts of the document tree.
DOM XML Specifies an extension to the core DOM for use with XML. DOM XML addresses the particular needs of XML, such as CDATA Sections, processing instructions, namespaces, and so on.
According to the DOM specification, we should be able to test for the availability of a particular aspect of the DOM specification using document.implementation.hasFeature() and pass it a string for the feature in question like “CORE” and a string for the version number—at this point “1.0” or “2.0.” The following script shows how you might detect the DOM support in a browser.
You’ll notice that the results shown in Figure 10-1 suggest that DOM support is spotty in the most popular browser, Internet Explorer.
The first step in understanding the DOM is to learn how it models an (X)HTML document.