JavaScript Answers

How to get list of data-* attributes using JavaScript?

Spread the love

To get list of data-* attributes using JavaScript, we use the dataset property.

For instance, we write

const attributes = element.dataset;
const cat =;

to get a list of data- attributes as an object with the element.dataset property.

We use the property to get the value of the element‘s data-cat attribute.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *