Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.
id
Type: unique id
A unique identifier so that you can identify the element with. You can use this as a parameter to getElementById() and other DOM functions and to reference the element in style sheets.

Example

<button id="foo" label="Click Me" oncommand="doSomething()"/>

<script>
function doSomething(){
    var myButton = document.getElementById('foo');
    myButton.setAttribute('label','The button was pressed');
}
</script>

A more abstract version of the above would be a

<button id="foo" label="Click Me" oncommand="setWidgetLabel(this, 'I was pressed')"/>
<script>
function setWidgetLabel(idName, newCaption){
   document.getElementById( idName.id ).setAttribute('label',newCaption)
}

</script>
Note: Not specifying the id attribute for a window or a prefwindow fills the console with the following warning message: Warning: Empty string passed to getElementById()

See also

Document Tags and Contributors

 Contributors to this page: Sheppy, trevorh, pippijn, Mossop, madarche, Marsf, Mgjbot, Ptak82, Okome, Pmash, Enn, Dria
 Last updated by: Sheppy,