document.createTextNode(data) creates a new Text node containing a string. MDN notes it can escape HTML characters — < and & stay as plain text, not markup. Append the node to show it on the page.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.createTextNode. Start with this line.
JavaScript
document.createTextNode(data)
Call
What it does
document.createTextNode(data)
Primary signature.
document.createTextNode(...)
Call with the arguments your case needs.
Built into the browser. Call createTextNode(...) on document — no import required.
MDN: Document.createTextNode() creates a new Text node. Pass a string (data) and you get a Text node you can append into the DOM.
No. MDN marks Document.createTextNode() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A Text node (MDN). Read text.data, text.nodeValue, or text.textContent for the string.
MDN notes this method can be used to escape HTML characters. Characters like < and & stay as plain text — they are not parsed as markup (unlike innerHTML).
Node.TEXT_NODE, which equals 3. You can also use text instanceof Text.
Use createTextNode when you need an actual Text node to insert, move, or split. Assigning element.textContent is shorter when you only want to replace all text inside an element.