DOM level 1 specifies this property as a member of the HTMLElement object.
HTML elements in MSIE are often identified using their ID value. This is a textual name added with the ID HTML tag attribute. Netscape 6.0 should support this more reliably than earlier versions of the browser.
The value of the ID HTML tag attribute is stored in this property. This is also used as a means of locating elements by ID value.
You can change the ID value of an element by setting this property since it has read and write access. However it is hard to think of a circumstance where that might be useful. It is really meant to be a read-only property.
DOM provides some help when searching for elements and you can use the getElementsById() method on the document object in a DOM compliant implementation. Note that a getElementsById() method is not supported on the individual HTML elements. This does mean that DOM compliant searches by ID will traverse the entire document if necessary.
DOM provides several other mappings and you can traverse a node hierarchy as well, so this is not likely to prove a severe limitation.
You must make sure that any value you assign to this property is unique within the document since it is used as part of the document navigation mechanism.
If you use the same ID value for more than one element it is not clear which one will be located first when the document hierarchy is traversed, although it is likely to be the first one that was defined.
In the case of objects with the same ID, you may be presented with a collection or array of objects rather than a single object. This can make it difficult to write general purpose scripts.
See also: | Element object, ID="..." |
Prev | Home | Next |
Element.hideFocus | Up | Element.innerHTML |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |