Set attribute (Beta)
Set attribute (Beta)
element.setAttribute(name, value) / element.setAttribute(index, entry)
Set a single attribute on an element.
This method supports two calling signatures:
-
Pass a name string and a value string to set an attribute by name. In this case you can bind the value by passing a
BindingValueobject, but you cannot bind the name. -
Pass an index and an
AttributeEntryobject to update the attribute at that position in the attributes array, with full binding support on both name and value.
To replace the entire set of attributes at once, use element.setAttributes().
Beta
These methods are in public beta and may change with future releases.
Syntax
Parameters
Signature 1 — set by name:
name: string — The name of the attribute to set.value: string — The string value to assign to the attribute.
Signature 2 — set by index:
index: number — The zero-based position of the attribute in the element’s attributes array.entry: AttributeEntry — An object specifying the name and value, each of which can be a string or aBindingValue.
Related types:
Returns
Promise<AttributeEntry>
A Promise that resolves to the updated attribute entry.