phuocng / this-vs-that

Understanding the difference between ˍˍˍ and ˍˍˍ in front-end development
https://phuoc.ng/collection/this-vs-that
MIT License
1.47k stars 99 forks source link

[BUG] ele.setAttribute vs ele.attribute #303

Open krausyd opened 2 months ago

krausyd commented 2 months ago

There is an error in the section When to use setAttribute instead of dot notation?, you mention the case of data- attributes:

Because they're not standard HTML attributes, you can't set them using dot notation. You have to use setAttribute.

This is not right. You can always use the dataset attribute, which is a named set, and use the array notation to set the value you want to set. Example:

ele.dataset['count'] = 10;

See the documentation here: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset