| JavaScript - The Legacy DOM | | Print | |
The Legacy DOM
The original client-side JavaScript DOM defines provides access to document content through properties of the Document object. Several read-only properties, such as title, URL, and lastModified provide information about the document as a whole. See the reference section for further details on these and all Document properties and methods. Other properties are arrays that refer to specific types of document content:
- forms[ ]
-
An array of Form objects representing the forms in a document.
- images[ ]
-
An array of Image objects representing the images that appear in a document.
- applets[ ]
-
An array of objects that represent the Java applets embedded in a document. JavaScript can actually be used to script Java and control these applets, but doing so is beyond the scope of this pocket reference.
- links[ ]
-
An array of Link objects representing the hyperlinks in the document.
- anchors[ ]
-
An array of Anchor objects representing the anchors (named positions created with the name attribute of the HTML <a> tag) in the document.
These arrays contain objects in the order they appear in the document. So the first form in a document is document.forms[0], and the third image is document.images[2]. Another way to refer to document forms, images, and applets is to give them names with the HTML name attribute:
<form name="address">...</form>
When an form, image, or applet is given a name in this way, you can use that name to look it up in the array, or to look it up directly as a property of the document itself:
document.forms["address"] // A named form
document.address // The same thing
The Form object is particularly interesting. It has an elements[ ] array that contains objects representing the elements of the form, in the order they appear in the form. See Input, Select, and Textarea in the reference section for details on these form elements.
The elements[ ] array of a Form works much like the forms[ ] array of a Document: it holds form elements in the order they appear in the form, but it also allows them to be referred to by name. Consider this HTML excerpt:
<form name='address'><input name='street'></form>
You can refer to the input element of the form in several ways:
document.forms[0].elements[0]
document.address.elements['street']
document.address.street
The legacy DOM does not provide any way to refer to document content other than forms, form elements, images, applets, links, and anchors. There is no array that provides a list of all <h1> tags, for example, nor is there any way for a script to obtain the actual text of a document. This is a shortcoming that is addressed by the W3C and IE 4 DOMs, as we'll see later. Although it is limited, the legacy DOM does allow scripts to dynamically alter some document content, as we'll see in the following subsections.
| Users' Comments (0) |
|
No comment posted




