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
    • Element Properties & Methods
      • Attributes
      • Custom Attributes
      • Styles
      • Text Content
        • Set Text Content
        • Get Text Content
      • Display Name
    • 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
  • Example
ElementsElement Properties & MethodsText Content

Get Text Content

Was this page helpful?
Previous

Display Name

Next
Built with

The text content of an element is automatically created as a child StringElement of that element. To retrieve the text content from an element, you’ll need to retrieve the child StringElement of your target element. Once you’ve retrieved the StringElement you can use the getText() method to get the text content of your 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}