What's the best way to get data attribute JavaScript values from an element? or How do I properly use

18 Replies, 1249 Views

If you're struggling to get data attribute javascript values, here’s a quick fix:

```js
const value = element.getAttribute('data-cool-stuff');
```

No fancy stuff, just works.

But `dataset` is nicer if you’re doing a lot of data-* stuff. Your call!

Messages In This Thread



Users browsing this thread: 1 Guest(s)