DOM Element.id Property
The id property gets or sets an element's id attribute.
Description
The id property reflects the element's id attribute: its unique identifier in the document. IDs are used by getElementById(), CSS #id selectors, fragment links and attributes such as for and aria-labelledby, so each must be unique on the page.
Changing an element's id can break CSS rules, links and ARIA relationships that refer to the old value, so avoid changing it after the page has loaded unless you update everything that depends on it.
IDs are case-sensitive and must not contain spaces. Elements with an id are also available as global variables with the same name in browsers, a legacy feature you shouldn't rely on; use getElementById() instead.
Syntax
element.id
element.id = valueValue
A string: the element's id attribute, or an empty string.
Example
Browser Support
The following information will show you the current browser support for the Element.id property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





