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

18 Replies, 1273 Views

Wow, thanks everyone! Didn’t expect so many replies.

I tried both `dataset` and `getAttribute()`—both work, but `dataset` does feel cleaner for my use case.

One follow-up: what if the data attribute is dynamically added? Does `dataset` pick that up automatically, or do I need to refresh something?

Also, big thanks for the MDN link—super helpful! 🚀

Messages In This Thread



Users browsing this thread: 1 Guest(s)