How to get the values of data attributes in JavaScript code?

Spread the love

Sometimes, we want to get the values of data attributes in JavaScript code.

In this article, we’ll look at how to get the values of data attributes in JavaScript code.

How to get the values of data attributes in JavaScript code?

To get the values of data attributes in JavaScript code, we use the dataset property.

For instance, we write

const points = element.dataset.points;

to get the value of the data-points attribute of the element.

Conclusion

To get the values of data attributes in JavaScript code, we use the dataset property.

Leave a Reply

Your email address will not be published.