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

set attributes w/multi-values #60

Open
bkardell opened this issue Dec 21, 2016 · 1 comment
Open

set attributes w/multi-values #60

bkardell opened this issue Dec 21, 2016 · 1 comment

Comments

@bkardell
Copy link
Collaborator

There's a proposal on discourse to allow the setting of multiple attribute values in much the same way that jQuery allows via .attr(PlainObject) via overloading setAttribute. I proposed there that the name setAttribute seems to imply singular attribute nature and that it would probably be both more intuitive and more successful as a standards proposal to give it another name. This is just my personal opinion, but it strikes me worth checking here to see how others feel and if anyone is planning on/willing to take up support more formally.

https://discourse.wicg.io/t/proposal-element-setattributes-object/1917/7

@jonathantneal
Copy link

The convenience of this method would be to clearly group attribute assignments so they are easier to read and understand.

element.setAttributes({
	id: 'nav-item-1',
	class: 'nav-item',
	'aria-controls': 'nav-item-1-submenu',
	'aria-haspopup': true,
	'aria-expanded': false
})

This is also convenient as we can’t hack around it with something like Object.assign(element.style, {}). This may also be convenient for readability if you are modifying some longAndDeep.elementReference or the presumed return of a querySelector(selector).

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

2 participants