element.getText()

Retrieves the text value from a String element.

Syntax

1element.getText(): Promise<null | string>

Returns

Promise<string>

A Promise that always resolves to a String value, which is the text content of the string element.

Example

1// Get Selected Element
2const selectedElement = await webflow.getSelectedElement();
3
4if (selectedElement?.textContent && selectedElement?.children) {
5
6 // Get Child Elements
7 const children = await selectedElement.getChildren();
8
9 // Filter string elements from children
10 const strings = children.filter(child => child.type === "String");
11
12 // Initialize an array to hold text content
13 let textContent = [];
14
15 // Loop over string elements to get text
16 for (const myString of strings) {
17 if (myString.type === "String") {
18 const text = await myString.getText();
19 textContent.push(text);
20 }
21 }
22
23 // Print text
24 console.log(textContent);
25}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessCanvasAnyAnyAnyAny
Built with