Element.setAttrs method
Element › setAttrs
Official
Sets multiple attributes on the element.Signature:
setAttrs(obj: Record<string, string | number | boolean | null>): voidParameters:
| Parameter | Type | Description |
|---|---|---|
| obj | Record<string, string | number | boolean | null> | The attributes to set. |
Returns: void
Example:
const element = createEl('p');element.setAttrs({ 'data-foo': 'bar', 'data-baz': 'qux',});console.log(element.getAttr('data-foo')); // barconsole.log(element.getAttr('data-baz')); // qux