webflow.elementBuilder(webflow.elementPresets.DOM)

Creates the root element for a new element structure, which can then append DOM elements to its hierarchy. This method is optimized for bulk creation, particularly useful when dealing with complex hierarchical designs. Before placing the on the canvas, set the HTML Tag of the DOM element using the element.setTag() method.

Limitations

DOM Elements: Currently, only DOM Elements can be created and inserted as root or child elements using this method.

Syntax

1webflow.elementBuilder(webflow.elementPresets.DOM): BuilderElement

Parameters

  • newElement: webflow.elementPresets.DOM> - The new element to be inserted into the hierarchy. This element is derived from the webflow.elementPresets object. Currently, only DOM elements can be inserted.

Returns

BuilderElement

A BuilderElement designed for creating and manipulating hierarchical structures.

Example

1// Get Selected Element
2const selectedElement = await webflow.getSelectedElement()
3
4// Build an element. We only support DOM elements and append for now.
5const rootElement = webflow.elementBuilder(webflow.elementPresets.DOM)
6
7// Append a DOM element to the element structure.
8const childElement = rootElement.append(webflow.elementPresets.DOM)
9childElement.setTag('svg')
10childElement.setAttribute("title", "hello");
11childElement.setStyles([myStyle])
12
13if (selectedElement?.children) {
14 // Add root element to the deisgner by appending to selected Element
15 await selectedElement.append(rootElement)
16}