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

22 Replies, 1538 Views

I’ve had bugs with javascript get data attribute too! Turns out I was mixing up hyphen-case and camelCase.

`.dataset` converts `data-my-attr` to `myAttr`, while `getAttribute()` keeps it as-is.

So if your code’s buggy, check your casing!

MDN has a great guide on this—worth a peek.

Messages In This Thread



Users browsing this thread: 1 Guest(s)