.textContent

String? Node.textContent

A property holding the text content under a node. It can also be set.

let text = node.textContent;

text holds the concatenation of all the text nodes of a node’s descendants.

node.textContent = text;

Replaces all the children of node with a text node with the content of text.

Examples

HTML:

<p>
    All
    <strong>large</strong>
    goats
    <em>are</em>
    delicious!
</p>

Get textContent

JavaScript:

let text = document.query("p").textContent;

Result is "All large goats are delicous!" (with more whitespace).

Set textContent

JavaScript:

document.query("p").textContent = "hi there";

HTML is now <p>hi there</p>.