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

18 Replies, 1242 Views

Hey! If you're trying to get data attribute javascript values, `element.dataset` is actually the cleanest way imo.

But if it feels like overkill, you can just use `getAttribute('data-something')`. Super simple and works everywhere.

Also, if your get data attribute javascript method isn’t working, double-check the casing—dataset converts `data-this-thing` to `thisThing`. Tripped me up once!

For modern JS, ditch jQuery—vanilla is totally fine here.

Messages In This Thread



Users browsing this thread: 1 Guest(s)