element.getAttribute(name)

Retrieve the value of the named HTML attribute of the DOMElement. Use this method instead of the ‘Custom Attribute’ methods.

Syntax

1element.getAttribute(name: string): Promise<null | string>

Parameters

  • name : string - The name of the attribute

Returns

  • Promise<String>: A promise that resolves to the value of the named HTML attribute for the DOMElement.
  • Promise<null>: If the attribute doesn’t exist, this method will return null.

Example

1// Get All Elements and find first DOM Element
2const elements = await webflow.getAllElements()
3const DOMElement = elements.find(element => element.type === "DOM")
4
5if (DOMElement?.type === "DOM") {
6
7 // Get DOM Element's Attribute by Name
8 const attribute = await DOMElement.getAttribute("MyAttribute")
9 console.log(attribute)
10
11} else {
12 console.log('No DOM Element Found')
13}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasAnyAnyAnyAny
Built with