CKTIS / JavaScript
document.createTextNode() — creating a text node
document.createTextNode(data) creates a Text node containing the supplied content without interpreting it as markup.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
document.createTextNode(data)document.createTextNode(data) returns a new Text node owned by the document. The required data argument specifies its content.
The node initially has no parent. Use appendChild() to attach it; creation alone does not change the page. Its content remains text, not a structure of elements.
The example attaches text to a detached element and checks its content and node type. This is a DOM API, not a feature of ECMAScript itself.
Examples
const container = document.createElement('p');
const text = document.createTextNode('<b>Hello</b> & welcome');
console.log(text.parentNode === null);
container.appendChild(text);
console.log(container.textContent);
console.log(container.childNodes.length);
console.log(container.firstChild.nodeType === Node.TEXT_NODE);Result
true <b>Hello</b> & welcome 1 true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.