Sometimes, we want to get list of data-* attributes using JavaScript.
In this article, we’ll look at how to get list of data-* attributes using JavaScript.
How to get list of data-* attributes using JavaScript?
To get list of data-* attributes using JavaScript, we use the element’s dataset
property.
For instance, we write
const attributes = element.dataset;
to use the element.dataset
object to get the data- attributes of element
.
The property keys would be the name after the hyphen.
And the values would be the attribute values.
Conclusion
To get list of data-* attributes using JavaScript, we use the element’s dataset
property.