Element.setAttr method
Element › setAttr
Official
Sets an attribute on the element.Signature:
setAttr(qualifiedName: string, value: string | number | boolean | null): voidParameters:
| Parameter | Type | Description |
|---|---|---|
| qualifiedName | string | The name of the attribute to set. |
| value | string | number | boolean | null | The value to set the attribute to. |
Returns: void
Example:
const element = createEl('p');element.setAttr('data-foo', 'bar');console.log(element.getAttr('data-foo')); // bar