HTML and CSS Reference
In-Depth Information
Because every object aside from the window object is nested within other objects, you
can indicate an object's location within the hierarchy using the notation
object1 . object2 . object3 ...
where object1 is at the top of the hierarchy, object2 is a child of object1 , object3 is
a child of object2 , and so on. Thus, to reference the document object displayed within
the browser window, you could use:
window.document
You do not always have to use a complete reference detailing the entire object hierarchy.
For example, when you simply use the document object reference, JavaScript assumes
that you are referring to the document displayed within the current browser window. If
your script works with multiple browser windows, you might need to explicitly indicate
the window containing the document object you want to access. For now, all of the
scripts you'll write will apply to the currently active document.
Referencing Object Collections
When more than one of the same type of object exists, these objects are organized into
structures called object collections . For example, the object reference
document.images
references all of the inline image objects in the current document—and implicitly within
the current browser window. Figure 13-6 lists some other examples of object collections
found within the document , navigator , and window objects.
Figure 13-6
Object collections
Object Collection
References
document.anchors
All anchors marked with the <a> tag
document.applets
All applets
document.embeds
All embed elements
document.forms
All Web forms
document. fname .elements
All form elements within the form fname
document.images
All inline images
document.links
All hypertext links
document.plugins
All plug-ins in the document
document.styleSheets
All style sheet elements
navigator.plugins
All plug-ins supported by the browser
navigator.mimeTypes
All MIME types supported by the browser
window.frames
All frames within the current browser window
To reference a specific object within a collection, you can use either
collection [ idref ]
or
collection . idref
where collection is a reference to the object collection, and idref is either an index
number representing the position of the object in the collection array or the value of the
id attribute assigned to the element. As with JavaScript's Array object, the first object in
 
Search WWH ::




Custom Search