asp.net.ph

Skip Navigation Links

ID Attribute | id Property

Language References


Sets or retieves the string identifying the object.

Syntax


Inline <element ID = sID...>
Script [ sID = ] object.id

Possible Values


sID Any alphanumeric string that begins with a letter. The underscore ( "_" ) may also be used.

The ID value can be assigned at design-time but is read-only at run-time.

Remarks

The id attribute assigns a unique identifier to an element. The attribute has several roles in HTML:

  • As a stylesheet selector.
  • As a target anchor for hypertext links.
  • As a means to reference a particular element from a script.
  • As the name of a declared OBJECT element.
  • For general purpose processing by user agents, like for identifying fields when extracting data from HTML pages into a database, translating HTML documents into other formats, etc.

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 only be referenced by ordinal position, as in objectID ( n ) .

Note that the id attribute shares the same name space as the name attribute when used for anchor names. Please consult the section on anchors with both name and id for more information.

Example

The following example demonstrates the setting of the ID attribute and the passing of this property into a function in order to manipulate the object to which it is attached.

<script language="JavaScript">
function checkCols ( oObject ) {
var iColumns = oObject.cols;
alert ( iColumns );
}
</script>
</head>
<body>
<table id=oTable border cols=3 
  onclick="checkCols ( this )">
<tr>
  <td>Column 1</td>
  <td>Column 2</td>
  <td>Column 3</td></tr>
</table>

This feature requires Microsoft® Internet Explorer® 4.0 or later.

 Show me 



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note