id attribute | id property
[This documentation is preliminary and is subject to change.]
Sets or retrieves the string identifying the object.
Syntax
| HTML | <element id="p" ... > |
|---|---|
| JavaScript | |
Property values
Type: String
any alphanumeric string that begins with a letter. The underscore (_) can also be used.
Remarks
The id is an SGML identifier used as the target for hypertext links or for naming particular objects in associated style sheets.
The id should be unique throughout the scope of the current document. If a document contains more than one object with the same identifier, the objects are exposed as a collection that can be referenced only in ordinal position.
In versions earlier than Microsoft Internet Explorer 5, this property is read-only.
Examples
This example gets the ID attribute of each cell of a table. When the user clicks a cell, the object of the cell is passed to a function which returns the object's ID.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/id.htm
<script>
function getID(oObject)
{
var id = oObject.id;
alert("This object's ID attribute is set to \"" + id + "\".");
}
</script>
<table border="">
<tr>
<td id="firstCell" onclick="getID(this);">Table Cell 1</td>
<td id="secondCell" onclick="getID(this);">Table Cell 2</td>
<td id="thirdCell" onclick="getID(this);">Table Cell 3</td>
</tr>
</table>
Build date: 3/8/2012
A nonextant id, which is a non null blank, is a strange data type, call it, 'hole':
Using such a nonextant id, hole, can disrupt JScript built-in functions:
e.g. SEE: getElementById() - caution .
- 7/23/2009
- Mr. Raymond Kenneth Petry