I came across 3 ways to store any data with HTMLElement object.
Can someone please suggest the best practice to associate any data with element object?
I prefer number 3 because it doesn't set any HTML attribute as in the case of 1 and 2. It's just like setting and getting any property on the object.
- Use setAttribute('nonStandardDataProperty')
- Use dataset property of HTMLElement object for example dataset.x for data-xattribute
- HTMLElement is object, so define any property and it will serve as data storage for that element