Get attribute value (Beta)

element.getAttributeValue(name) / element.getAttributeValue(index)

Get the value of a single attribute on an element.

You can look up the attribute by its name string or by its zero-based index in the attributes array. The returned value may be a plain string or a BindingValue when the attribute value is bound to a variable or component prop.

To get the resolved string value with any binding evaluated, use element.getResolvedAttributeValue().

Beta

These methods are in public beta and may change with future releases.

Syntax

1element.getAttributeValue(name: string): Promise<string | BindingValue | null>
2element.getAttributeValue(index: number): Promise<string | BindingValue | null>

Parameters

  • name : string — The name of the attribute whose value to retrieve.
  • index : number — The zero-based position of the attribute in the element’s attributes array.

Returns

Promise<string | BindingValue | null>

A Promise that resolves to the attribute value, a BindingValue if the value is a binding reference, or null if no attribute with the given name or index exists.

Example

1const element = await webflow.getSelectedElement()
2
3if (element && element.attributes) {
4 // Look up by name
5 const value = await element.getAttributeValue('data-label')
6 console.log(value) // 'primary'
7
8 // Look up by index
9 const first = await element.getAttributeValue(0)
10 console.log(first) // 'primary'
11}

Designer Ability

Checks for authorization only.

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasAnyAnyAnyAny