Sometimes, we want to get HTML “data-” attribute value with JavaScript.
In this article, we’ll look at how to get HTML “data-” attribute value with JavaScript.
How to get HTML “data-” attribute value with JavaScript?
To get HTML “data-” attribute value with JavaScript, we use the getAttribute method.
For instance, we write
const one = obj.getAttribute("data-uid");
to call getAttribute on element obj to get the value of the data-uid attribute.
Conclusion
To get HTML “data-” attribute value with JavaScript, we use the getAttribute method.