Sometimes, we want to get an element’s ID with JavaScript.
In this article, we’ll look at how to get an element’s ID with JavaScript.
How to get an element’s ID with JavaScript?
To get an element’s ID with JavaScript, we use the id
property.
For instance, we write
const id = myDOMElement.id;
to get the ID of the myDOMElement
element with myDOMElement.id
.
Conclusion
To get an element’s ID with JavaScript, we use the id
property.