W3cubDocs

/DOM

element.id

The Element.id property represents the element's identifier, reflecting the id global attribute.

It must be unique in a document, and is often used to retrieve the element using getElementById. Other common usages of id include using the element's ID as a selector when styling the document with CSS.

Note: identifiers are case-sensitive, but you should avoid creating IDs that differ only in the capitalization (see Case sensitivity in class and id names).

Syntax

var idStr = elt.id; // Get the id.
elt.id = idStr; // Set the id
  • idStr is the identifier of the element.

Specifications

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

  • The DOM id global attribute.

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/element/id