webflow.getSelectedElement()
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
webflow.getSelectedElement(): Promise<null | AnyElement>
Returns
Promise<AnyElement | null
>
null
>A Promise that resolves to one of the following:
null
: If an element is not currently selected in the DesignerAnyElement
: 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.
// Get Selected Element
const element = await webflow.getSelectedElement();
// Print element info
if (element) {
console.log(`Selected Element ID: ${element.id}`);
console.log(`Element type: ${element.type}`);
// Perform some action with the selected element
} else {
console.log("No element is currently selected.");
}
Designer Ability
Checks for authorization only
Designer Ability | Locale | Branch | Workflow | Sitemode |
---|---|---|---|---|
canAccessCanvas | Any | Any | Any | An |