1. Home
  2. Javascript
  3. Get data attributes

Use dataset property to return an object containing all data attributes set on the element. You can also get value of a particular data attribute by using dot notation and referencing the unique name part of the attribute.

#javascript#data#attribute
// <div data-color="red" data-shape="square" data-count="4"></div>

element.dataset // { color: "red", shape: "square", count: "4" }
element.dataset.count // "4"
copy
Full Javascript cheatsheet