Did I use the correct way to get the attribute value?
Thank you very much.
A Pen by Christian Barrameda (codepen.io)
-Burds
Hi @Burds and welcome to the community
Yes, this is the correct way.
You can make the code simpler by removing the template string and the expression code. So this would be fine:
e.target.getAttribute('data-color')
As an alternative when working with data-*
attribute, you could also use dataset
:
e.target.dataset.color
This will give the same result as your code.
I hope that helps.
Have a nice day,
Michael