Element.id (Property)

The value of the ID tag attribute in the HTML tag that represents this element.


DOM level - 1
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
Property/method value type:String primitive
JavaScript syntax:-myElement.id
HTML syntax:<ELEMENT_TAG ID="anIDValue">
Argument list:anIDValueA valid (and unique within the document) ID value

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.


See also:Element object, ID="..."