home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Dynamic HTML: The Definitive Reference, 2rd Ed.Dynamic HTML: The Definitive ReferenceSearch this book

3.3. Two Types of Containment

If you have worked with JavaScript and the scriptable DOM Level 0 in early browsers, you are aware that objects in this model have a containment hierarchy of their own—an object containment hierarchy. The window object, which represents the content area of a browser window or frame, is at the top of the hierarchy. The window object contains objects such as the history, location, and document objects. The document object contains objects such as images and forms, and, among the most deeply nested objects, the form object contains form control elements, such as text fields and radio buttons.

Document object containment is vitally important in the comparatively limited DOM Level 0 because the hierarchy defines how you refer to objects and their methods and properties in your scripts. References usually start with the outermost element and work their way inward, using the JavaScript dot syntax to delimit each object. For example, here's how to reference the content of a text field (the value property) named zipCode inside a form named userInfo:


More modern DOMs, especially the W3C DOM Level 1 and later, let the structure of the document dictate element containment as defined by the tag geography of a document. In this context, you see frequent references to the notion of parents and children, where a nested element is a child of its parent container. CSS relies very heavily on element containment.

While the terms "parent" and "child" imply an object orientation, this is not the case in the DOM. An img element nested in a td element, for example, does not inherit the parent td element's id property. But when applying style sheets to an element containment structure, the concept of inheritance is alive and well: an element can inherit a style assigned to another element higher in the element containment hierarchy.

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.