HTML DOM createTextNode() method
Example
Create a text node:
var btn=document.createTextNode("Hello World");
Output result:
Hello World
Try it »
HTML elements usually consist of an element node and a text node.
To create a heading (H1), you must create the "H1" element and a text node:
Example
Create a heading:
var h=document.createElement("H1")
var t=document.createTextNode("Hello World");
h.appendChild(t);
Output result:
Hello World
Try it »
Definition and Usage
createTextNode() can create a text node.
Browser support





All major browsers support the createTextNode() method
Syntax
document.createTextNode(
text
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| text | String | Required. The text of the text node. |
Return Value
| Type | Description |
|---|---|
| Text node object | Create a text node |
Technical Details
| DOM version | Core Level 1 Document Object |
|---|
Document Object