Easy Tutorial
❮ Prop Style Filter Jsref Regexp Hex ❯

HTML DOM createTextNode() Method

Document Object

Example

Create a text node:

Output result:

HTML elements are usually composed of element nodes and text nodes.

To create a heading (H1), you must create the "H1" element and the text node:

Example

Create a heading:

var h = document.createElement("H1");
var t = document.createTextNode("Hello World");
h.appendChild(t);

Output result:

Hello World


Definition and Usage

The createTextNode() method creates a text node.


Browser Support

All major browsers support the createTextNode() method.


Syntax

Parameters

Parameter Type Description
text String Required. The text of the text node.

Return Value

Type Description
Text node object The created text node.

Technical Details

| DOM Version | Core Level 1 Document Object | | --- | --- |


Document Object

❮ Prop Style Filter Jsref Regexp Hex ❯