HTML DOM createTextNode()Method
Example
Create a text node:
var btn=document.createTextNode("Hello World");
Output:
Hello World
Try it Yourself »
HTML elements usually consist of element nodes and text nodes.
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);
var t=document.createTextNode("Hello World");
h.appendChild(t);
Output:
Hello World
Try it Yourself »
Definition and Usage
createTextNode() can create a text node.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the createTextNode() method
Syntax
document.createTextNode(text)
Parameters
| Parameter | Type | Description |
|---|---|---|
| text | String | Required. The text of the text node. |
Return Value
| Type | Description |
|---|---|
| A text node object | Create a text node |
Technical Details
| DOM Version | Core Level 1 Document Object |
|---|
Other Extensions
Document Object