For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Resources
Get started
ReferenceGuidesExamplesChangelog
ReferenceGuidesExamplesChangelog
  • Designer API
    • Introduction
    • Getting Started
    • Webflow CLI
    • Error Handling
    • App Modes
  • Elements
    • Creating & Retrieving Elements
      • Get selected element
      • Set selected element
      • Get element children
      • Get the parent component
      • Get all elements
      • Insert element before target element
      • Insert element after target element
      • Nest element as first child
      • Nest element as last child
      • Bulk Add Elements
      • Remove element
    • Element Properties & Methods
    • Element Types & Methods
  • Styles
    • Managing Style Properties
    • Managing Variable Modes
  • Components
  • Variables & Collections
    • Variable Collections
    • Variables
    • Variable Modes
  • Assets
  • Pages & Folders
  • Utilities
    • User Events & Notifications
    • App Intents & Connections
  • Additional Resources
    • API Playground
    • FAQs
LogoLogo
Resources
Get started
On this page
  • webflow.getSelectedElement()
  • Syntax
  • Returns
  • Example
  • Designer Ability
ElementsCreating & Retrieving Elements

Get selected element

Was this page helpful?
Previous

Set selected element

Next
Built with

webflow.getSelectedElement()

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

The returned element object provides access to all element properties (like type, id, and styles) and exposes methods such as getChildren(), getStyles(), and getCustomAttributes() for working with the element programmatically.

Syntax

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

Returns

Promise<AnyElement | null>

A Promise that resolves to one of the following:

  • 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.
  • null: If an element is not currently selected in the Designer

Example

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 // If the element has children, print the child elements
10 if(element.children){
11 const children = await element.getChildren();
12 console.log(`Child elements: ${children}`);
13 }
14
15} else {
16 console.log("No element is currently selected.");
17}

Try this example

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasAnyAnyAnyAny