DOM Element
The custom element, also known as the DOM Element, is a placeholder element that you can add any HTML custom attribute, tag, or text to — thereby “creating” that element on the canvas. This is useful for adding HTML elements to the canvas that aren’t available as native Webflow elements.
Once you add the custom element to the canvas, you’re able to use the below methods, which are only available to the DOM element, as well as the more general element methods to manage children, styles, and text content.
Properties
Methods
element.getTag()
Retrieve the HTML tag of the element.
Syntax
Returns
- Promise<String> : If the DOMElement has a tag, a promise that resolves to the tag value.
- Promise<
null
>: If the DOMElement does not have a tag, a promise that resolves tonull
Example
Designer Ability
Checks for authorization only
element.setTag(tag)
Set the value of the specified HTML tag of the DOMElement.
Syntax
Parameters
- tag :
string
- The HTML tag to set for the element
Returns
Promise<null
>
A promise that resolves to null
Example
Designer Ability
element.getAllAttributes()
Retrieve all HTML attributes for the DOMElement. Use this method instead of the ‘Custom Attribute’ methods.
Syntax
Returns
Promise<NamedValue> - {name: string, value:string }
A promise that resolves to an array of, NamedValue
attribute objects.
Example
Designer Ability
Checks for authorization only
element.getAttribute(name)
Retrieve the value of the named HTML attribute of the DOMElement. Use this method instead of the ‘Custom Attribute’ methods.
Syntax
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 does not exist, this method will returnnull
.
Example
Designer Ability
Checks for authorization only
element.setAttribute(name, value)
Set the value of the specified HTML attribute for the DOMElement. Use this method instead of the ‘Custom Attribute’ methods.
Syntax
Parameters
- name:
string
- The name of the attribute - value:
string
- The value of the attribute
Returns
Promise<null
>
A promise that resolves to null
Example
Designer Ability
element.removeAttribute(name)
Removes the specified HTML attribute from the DOMElement. If the attribute does not exist, this method will do nothing. Use this method instead of the ‘Custom Attribute’ methods.
Syntax
Parameters
- name:
string
- The name of the attribute
Returns
Promise<null
>
A promise that resolves to null