What's the best way to use javascript get data attribute from an element? or How do you properly use

22 Replies, 1553 Views

If you’re using jQuery, you can do `$(el).data('attr')`, but be careful—it caches values after the first read!

Vanilla JS is safer for javascript get data attribute stuff.

Also, `.dataset` is more “modern” but `getAttribute()` is more predictable.

Messages In This Thread



Users browsing this thread: 1 Guest(s)