Chapter 10. DOM: The Document Object Model


One of the most significant changes associated with JavaScript was the W3C's work in conjunction with all browser vendors (including Netscape and Microsoft) to create a consistent underlying object model. All major browsers agreed to support this model, eliminating most, if not all, cross-browser compatibility issues. Though the default Browser Object Model discussed in the last chapter provided a great deal of functionality, much of the implementation of the model was based on influence of one browser, or browser company, over another. Over time, this led to a great deal of cross-browser incompatibility, hampering advanced uses of JavaScript until the last few years.

This changed with the release of the W3C's recommended Document Object Model (DOM). From the W3C comes this description:

The Document Object Model is 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.

The first release of the DOM was DOM Level 1, issued as a recommendation in 1998. This release helped define the infrastructure for the DOMthe schema and Application Programming Interface (API) that future versions of the DOM could use as a base of functionality. It also helped establish a core component of each recommendation that is required for a DOM-compliant user agent (such as a browser); all other specifications are issued as separate, but related, optional modules. This approach helped encourage early adoption, and maintain consistency with critical elements.

DOM Level 2 followed in 2000 and expanded on the earlier Level 1 release, while still maintaining consistency with the earlier release. You've already been exposed to one aspect of this release with the Level 2 event handling in Chapter 3. The DOM Level 2 added increased support for Cascading Style Sheets, improved access for document elements, and namespace support in the XML recommendation.

The DOM Level 3 was released in 2004 and at the time this book was written, had very little support in most major browsers. In addition to extensions and improvements to the previous releases, this version adds modules to extend support for web services, as well as increased support for XML. The DOM Level 3 is the last of the W3C levelsat least, the last planned W3C level release.

This chapter doesn't provide a complete reference for all of the objects in the DOM APIs. These are listed quite nicely at the W3C web site in a URL which should persist as long as the specification. Instead, I've focused on representative objects, how they interact with one another, and their impact within the browser page.

The W3C DOM Level 1 Recommendation can be seen at http://www.w3.org/TR/REC-DOM-Level-1/; DOM Level 2 recommendation at http://www.w3.org/TR/DOM-Level-2-HTML/; and the Level 3 Xpath Specification at http://www.w3.org/TR/DOM-Level-3-XPath/.

Of more interest is the ECMAScript binding (the implementation of the APIs you'll use with JavaScript) for each specification version. The Level 1 script binding for both HTML and Core is at http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html. The Level 2 script binding for the Core API is at http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html, and the Level 2 script binding for the separate HTML module is at http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/ecma-script-binding.html. The ECMAScript binding for the third, and final, DOM Core API is at http://www.w3.org/TR/DOM-Level-3-Core/ecma-script-binding.html.





Learning JavaScript
Learning JavaScript, 2nd Edition
ISBN: 0596521871
EAN: 2147483647
Year: 2006
Pages: 151

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net