X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM createTextNode() Method

Document Object Reference Document Object

Example

Create a text node:

var btn=document.createTextNode("Hello World");

The result will be:

Hello World

Try it yourself »

HTML elements often consists of both an element node and a text node.

To create a header (H1), you must create both an "H1" element and a text node:

Example

Create a header:

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

The result will be:

Hello World


Try it yourself »


Definition and Usage

The createTextNode() method creates a Text Node with the specified text.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The createTextNode() method is supported in all major browsers.


Syntax

document.createTextNode(text)

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 Reference Document Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook