HTML DOM Document createTextNode()
Examples
Create a text node and append it to the document:
Create a <h1> element with a text node:
const textNode = document.createTextNode("Hello World");
h1.appendChild(textNode);
Create a <p> element with a text node:
const textNode = document.createTextNode("Hello World");
para.appendChild(textNode);
HTML Elements are Nodes
All HTML elements are nodes.
Elements are nodes. Attributes are nodes. Texts are nodes.
Some elements contain other nodes.
Some elements contain text nodes.
Some elements contain attribute nodes.
Description
The createTextNode() method creates a text node.
Syntax
Parameters
The text for the node.
Return Value
Browser Support
document.createTextNode() is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera | IE |
| Yes | Yes | Yes | Yes | Yes | 9-11 |