id property is an identifier, used to represent an element.
id must be unique in an document.
It can be retrieved using getElementById.
It can also be used as a selector to set CSS property.
Example - Get id value of an element
- In the above example we have created a button (Get id value).
- Using the id property, we are getting the id if the element and storing it in elem variable.
- Next we are displaying the value (alert(elem);).