We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

element.id Redirect 1


Gets or sets the element's identifier (attribute id).


var idStr = element.id; // Get the id.
element.id = idStr; // Set the id

where idStr is the ID of the element.


The ID must be unique in a document, and is often used to retrieve the element using getElementById.

In some documents (in particular, HTML, XUL, and SVG), the id of an element can be specified as an attribute on the element like so: <div id="main-content">.

However you can't use this attribute in a custom XML document without correctly specifying the type of the id attribute in the DOCTYPE.

Other common usages of id include using the element's ID as a selector when styling the document with CSS.

Note that IDs are case-sensitive, but you should not create IDs that differ only in the capitalization (see Case Sensitivity in class and id Names).


Specification Status Comment
Document Object Model (DOM) Level 2 HTML Specification Recommendation  


Document Tags and Contributors

Last updated by: Sheppy,