APIsChangelog
Log In
APIs

Link Element

The Link element represents an Link Block in the Webflow Designer.

Properties

PropertyDescriptionTypeExample
idUnique identifier for the element composed of two identifiers, the component and the element.object{component: "64c813...", element: "5edf8e59-71f9..."}
typeSpecifies the type of the element.string"Link"
childrenIndicates whether the element can contain child elements.booleanfalse
customAttributesIndicates whether the element can have custom attributes.booleantrue
stylesIndicates whether the element can contain styles.booleantrue
textContentIndicates whether the element can contain text contentbooleanfalse

Methods

element.getTarget()

Get the target value of the link block element.

Syntax

element.getTarget(): Promise<null | string | Page | AnyElement | Asset>;

Returns

Promise<null | string | Page | AnyElement | Asset>

A Promise that resolves to an the target value of the link. The target value can be a string, Page, Element, or an Asset object.

Example

const elements = await webflow.getAllElements() // Get All Elements
const links = elements.filter((element) => element.type === 'Link') // Filter for Link elements

// Print target value of each link element
for (const link of links) {
  const targetValue = await link.getTarget()
  console.log(`ID: ${link.id.element}, Target Value: ${targetValue}`)
}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasanyanyanyany

element.setSettings(mode, target, metadata)

Apply settings for a Link Block element. Including the type of link, its value, and metadata settings.

Syntax

element.setSettings( 
  mode: 'url' | 'page' | 'pageSection' | 'email' | 'phone' | 'attachment';
  target: string | Page | Element | Asset;
  metadata?: {openInNewTab?: boolean; subject?: string;}): Promise<null>

Parameters

  • Mode: enum - The type of link to set. Can be a url, email, or phone number; a link to another page or pageSection; as well as an attachment.
  • Target: string | Page | Element | Asset - The value of the link. The value type determined by the selected mode. For example, if the link mode is "attachment" the method expects an Asset object.
  • Metadata: object - Optional metadata for link settings:
    • openInNewTab: boolean - Choose to open the link in a new tab
    • subject: string - The subject line of an email link.

Returns

Promisenull

A Promise that resolves to null

Example

// Get Selected Element
const element = await webflow.getSelectedElement()

if (element) {
  const newLink = await element.after(webflow.elementPresets.LinkBlock) // Create new link element
  await newLink.setSettings('url', 'https://www.webflow.com', {openInNewTab: true}) // Set link element settings
                            const targetValue = await newLink.getTarget() // Get target value
  console.log(targetValue)
}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canEditAntAnyCanvasAny