webflow.getSelectedElement()

Retrieve the element that the user has selected in the Webflow Designer.

The returned element object can be further queried using element-level properties (eg. type, styles) and methods (eg. getChildren())

Syntax

1webflow.getSelectedElement(): Promise<null | AnyElement>

Returns

Promise<AnyElement | null>

A Promise that resolves to one of the following:

  • null: If an element is not currently selected in the Designer
  • AnyElement: An object that represents the various element types available in a Webflow project. See a full list of supported element types in the Designer Extension type definitions.
1// Get Selected Element
2const element = await webflow.getSelectedElement();
3
4// Print element info
5if (element) {
6 console.log(`Selected Element ID: ${element.id}`);
7 console.log(`Element type: ${element.type}`);
8
9 // Perform some action with the selected element
10} else {
11 console.log("No element is currently selected.");
12}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasAnyAnyAnyAn