Text Content
Managing text content is essential for keeping content fresh and relevant. These methods let you handle an element’s text, ensuring it’s always up-to-date.
To effectively use the methods, choose an element that already has its textContent
property set to true
. This property is read-only, so it’s important to select elements that have this attribute. Using these methods with elements that don’t have this property will return an error.
Methods
element.setTextContent(content)
Set text content for an element. Be sure to check that an element has its textContent
property set to true.
Syntax
Parameters
content
:string
- Text to add to the element
Returns
Promise<null
>
A Promise that resolves to null
.
Example
Designer Ability
Getting Text Content
The textContent
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 get 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.