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 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.
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.
<script type="text/javascript">
function getID(oObject)
{
var id = oObject.id;
console.log("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>
See also
- style
- a
- abbr
- address
- area
- b
- base
- bdo
- blockQuote
- body
- br
- button
- caption
- cite
- code
- col
- colGroup
- comment
- custom
- dd
- del
- div
- dl
- dt
- em
- embed
- fieldSet
- form
- head
- hn
- hr
- html
- i
- iframe
- img
- input type=button
- input type=checkbox
- input type=file
- input type=hidden
- input type=image
- input type=password
- input type=radio
- input type=reset
- input type=submit
- input type=text
- ins
- kbd
- label
- legend
- li
- link
- map
- object
- ol
- optGroup
- option
- p
- pre
- q
- rt
- ruby
- s
- samp
- script
- select
- small
- span
- strong
- styleSheet
- sub
- sup
- table
- tBody
- td
- textArea
- tFoot
- th
- tHead
- title
- tr
- u
- ul
- var
Build date: 11/28/2012