Skip to content

set attributes w/multi-values #60

Open

Description

@bkardell

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

Activity

  1. jonathantneal commented on Dec 22, 2016

    @jonathantneal

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions