Web APIs
Node.textContent
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.textContentReturn 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);