Web APIs

Document.createTextNode()

Try the free JavaScript compiler

Construct a text node without parsing the supplied string as markup. Append it where plain text is intended. Example console output: <b>note</b> 0.

Formal Syntax & Structure

javascript syntaxjavascript
document.createTextNode(data)

Parameters & Attributes

NameTypeDescription
datastringLiteral text.

Return Value

Text

New text node.

Working Example

Example Snippetjavascript
const p=document.createElement("p"); p.append(document.createTextNode("<b>note</b>")); console.log(p.textContent,p.children.length);
JavaScript Reference