StringElements

The StringElement represents a string text element that can be added to the Webflow canvas. The StringElement object extends several interfaces, providing various controls over the element.


Methods

Get Text

getText(): string

Description: Gets text on from a StringElement

Returns: Contents of StringElement as string

const text = element.getText()
// Use the text

Set Text

setText(text: string)

Description: Sets text on a StringElement

Parameters

  • text: string - The new text for your StringElement
const myText = myStringElement.setText("My New Text")

Detach from Canvas

detach(): Promise<undefined>

Description:Detaches the StringElement from the Designer Canvas.

The detach method is used to remove an element from the Webflow Designer's canvas. Calling detach will remove the element from the visual representation of the website in the Designer, but does not delete the local reference to the element. This means you can still manipulate the element in your code after calling detach.

Returns: A Promise that resolves to undefined.

await myStringElement.detach()
// The element has been detached

Destroy

destroy(): undefined

Description: Remove the local reference to an element and trigger the cleanup process After you call destroy, you should no longer use the element in your code. This method does not remove the element from the Designer's canvas. If you want to remove the element from the canvas, you should call detach before destroy.

Returns: undefined

myStringElement.destroy();
// The element has been destroyed

Save StringElement

save(): Promise<undefined>

Description: Saves changes made to the StringElement back to the Designer.

Returns: A Promise that resolves to undefined.

await myStringElement.save();
// The element has been saved

Properties

PropertyDescription
idA read-only string that uniquely identifies the StringElement.
typeA read-only string that specifies the type of the element. For StringElement, it is always 'String'.
pluginA read-only string indicating that the StringElement is a basic Webflow plugin.
textContentA read-only boolean indicating that the StringElement can have text content.
childrenA read-only boolean indicating that the StringElement cannot have child elements.
stylesA read-only boolean indicating that the StringElement cannot have styles.
domIdA read-only boolean indicating that the StringElement cannot have a DOM ID.
customAttributesA read-only boolean indicating that the StringElement cannot have custom attributes.
configurableA read-only boolean indicating that the StringElement is configurable.