Web APIs
Document.createTextNode()
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
| Name | Type | Description |
|---|---|---|
| data | string | Literal 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);