Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krausyd opened this issue Sep 6, 2024 · 0 comments
Open

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

krausyd opened this issue Sep 6, 2024 · 0 comments

Comments

@krausyd
Copy link

krausyd commented Sep 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant