Web APIs

Node.textContent

Try the free JavaScript compiler

Setting textContent replaces child content with literal text. It does not interpret HTML markup. For displaying user-supplied text this avoids HTML parsing.

Formal Syntax & Structure

javascript syntaxjavascript
node.textContent

Return Value

string | null

Text content; null for certain node types.

Working Example

Example Snippetjavascript
const box=document.createElement("div");box.textContent="<b>Hi</b>";console.log(box.textContent,box.children.length);
JavaScript Reference