style.getProperty(prop, options?)

Retrieve the value of a specific property in a Style object.

Syntax

1 style.getProperty(prop: StyleProperty, options?: BreakpointAndPseudo): Promise<null | PropertyMap[p]>

Parameters

  • **prop **: StyleProperty: The name of the style property to retrieve. See the style properties list for an index of CSS properties and their accepted value types.
  • options : BreakpointAndPseudo {breakpoint: BreakpointId, pseudo: PseudoStateKey?}- An optional parameter to filter properties based on a breakpoint and/or pseudo-class, also known as a pseudo-state.

    • BreakpointId: "xxl" | "xl" | "large" | "main" | "medium" | "small" | "tiny" - An optional identifier of the breakpoint size, also known as media query, in the Designer.
    • PseudoStateKey: "noPseudo" | "nth-child(odd)" | "nth-child(even)" | "first-child" | "last-child" | "hover" | "active" | "pressed" | "visited" | "focus" | "focus-visible" | "focus-within" | "placeholder" | "empty" | "before" | "after" - An optional identifier for the pseudo-classes of an element that can be targeted and styled using CSS.

Returns

Promise<PropertyMap | Variable | null>

Returns a Promise that resolves to:

    • PropertyMap[p] - The value of the provided style property, if one exists.
  • ColorVariable | SizeVariable | FontFamilyVariable - A Variable object that represents the value of the provided style property.
  • null - If value does not exist for the provided style property, this method will return null.

Example

1// Get Selected Element
2const selectedElement = await webflow.getSelectedElement()
3
4// Get Element Styles
5if (selectedElement?.styles) {
6
7 const styles = await selectedElement.getStyles()
8 const selectedPropertyList = await Promise.all(styles.map(async style => {
9
10 const styleName = await style.getName()
11 const property = await style.getProperty(propertyName)
12 console.log(`Style Name: ${styleName}, ${propertyName}: ${property}`)
13
14 }))
15
16 }

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasAnyAnyAnyAn