Insert element before target element

element.before(newElement)

Insert a new element onto the page before the target element.

Syntax

1element.before(newElement: ElementPreset | Component): Promise<<AnyElement>

Parameters

  • newElement: webflow.elementPresets.<preset> - The new element to be inserted into the hierarchy. This element is derived from the webflow.elementPresets object, which contains all Webflow elements that can be inserted onto the canvas.

Returns

Promise<AnyElement>

A Promise that resolves to an AnyElement object.

AnyElement represents the various element types available in a Webflow project. See a full list of supported element types in our Designer Extension type definitions.

Example

1// Get Selected Element
2const selectedElement = await webflow.getSelectedElement()
3
4if (selectedElement) {
5
6 // Insert DIV before selected Element
7 const newDiv = await selectedElement.before(webflow.elementPresets.DivBlock)
8
9 // Print element details
10 console.log(`${JSON.stringify(newDiv)}`)
11
12}

App Mode

Designer AbilityLocaleBranchWorkflowSitemode
canDesignPrimaryMainCanvasDesign