Language References
Specifies an auto-generated unique identifier for the object.
HTML |
N/A |
Script |
[ sID = ] object.uniqueID |
sID |
Specifies a unique identifier for the element. |
The property is read-only with no default value.
When applied to the document object, this property causes the browser to automatically generate a new identifier that can then be assigned to an element’s ID property.
When applied to an element, a new ID is generated and assigned to the element the first time the property is retrieved. Every subsequent access to the property on the same element returns the same ID.
Note that the unique identifier generated is not guaranteed to be the same every time the page is loaded.
The following examples illustrate two different scenarios where the uniqueID property can be used.
The first example demonstrates how the uniqueID property can be used to hook up an element to a function defined within a behavior. From a behavior, the sample sets up a timer to fire every second.
The sample defines two tick ( ) functions: one on the scriptlet, and one on the page. Every time the timer fires, the behavior-defined tick ( ) function is called. To ensure that the correct tick ( ) function gets called, the sample uses the uniqueID property to hook up the element to the tick ( ) function defined in the behavior's namespace.
<METHOD NAME=tick />
<script language="JSCRIPT">
var numTicks = 0;
window.attachEvent ( "onload", onload );
function onload ( ) {
window.setInterval ( uniqueID+ ".tick ( )", 1000 );
}
function tick ( ) {
window.status = "Ticking: " +
numTicks++ + " milliseconds";
}
</script>
This feature requires Microsoft® Internet Explorer® 5 or later.
Show me
The second example demonstrates how the property provides a means for the browser to auto-generate a unique ID for an element that was inserted into the page by a behavior.
<METHOD NAME=tick />
<script language="JSCRIPT">
window.attachEvent ( "onload", onload );
function onload ( ) {
// Specifying an id=document.uniqueID ensures
// that a unique identifier will be assigned
// to the element being inserted into the page
// by the scriptlet.
newTextAreaID = element.document.uniqueID;
element.document.body.insertAdjacentHTML ( "beforeEnd",
"<p><TEXTAREA STYLE='height: 200 ;width: 350' id= " +
newTextAreaID + "></TEXTAREA>" );
}
</script>
DHTML Behaviors, Implementing Behaviors in Script