Home > Articles > Open Source > Ajax & JavaScript

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

10.6 Summary of the DOM Objects and Collections

As you've seen in the preceding sections, the objects and collections in the W3C DOM give you flexibility in manipulating the elements of a web page. We've shown how to access the objects in a page, how to access the objects in a collection, and how to change element styles dynamically.

The W3C DOM allows you to access every element in an XHTML document. Each element in a document is represented by a separate object. The diagram in Fig. 10.6 shows many of the important objects and collections provided by the W3C DOM. Figure 10.7 provides a brief description of each object and collection in Fig. 10.6.

Fig. 10.6

Fig. 10.6 W3C Document Object Model.

Fig. 10.7. Objects and collections in the W3C Document Object Model.

Object or collection

Description

Objects

window

Represents the browser window and provides access to the window's document object. Also contains history and location objects.

document

Represents the XHTML document rendered in a window. Provides access to every element in the document and allows dynamic modification of it. Contains collections for accessing all elements of a given type.

body

Provides access to the body element of an XHTML document.

history

Keeps track of the sites visited by the browser user. The object provides a script programmer with the ability to move forward and backward through the visited sites.

location

Contains the URL of the rendered document. When this object is set to a new URL, the browser immediately navigates to the new location.

Collections

anchors

Collection contains all the anchor elements (a) that have a name or id attribute. The elements appear in the collection in the order in which they were defined in the XHTML document.

forms

Contains all the form elements in the XHTML document. The elements appear in the collection in the order in which they were defined in the XHTML document.

images

Contains all the img elements in the XHTML document. The elements appear in the collection in the order in which they were defined in the XHTML document.

links

Contains all the anchor elements (a) with an href property. The elements appear in the collection in the order in which they were defined in the XHTML document.

For a complete reference on the W3C Document Object Model, see the DOM Level 3 recommendation from the W3C at http://www.w3.org/TR/DOM-Level-3-Core/. The DOM Level 2 HTML Specification (the most recent HTML DOM standard), available at http://www.w3.org/TR/DOM-Level-2-HTML/, describes additional DOM functionality specific to HTML, such as objects for various types of XHTML elements. Keep in mind that not all web browsers implement all features included in the specification.

  • + Share This
  • 🔖 Save To Your Account