Latest web development tutorials

HTML DOM createTextNode () method

Document Object Reference Document Object

Examples

Create a text node:

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

Output:

Hello World

try it"

HTML element is usually caused by several element nodes and text composition.

Create a header (H1), you must create the "H1" elements and text nodes:

Examples

Create a title:

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

Output:

Hello World


try it"

Definition and Usage

createTextNode () to create a text node.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support createTextNode () method


grammar

document.createTextNode( text )

parameter

参数 类型 描述
text String 必须。文本节点的文本。

return value

类型 描述
文本节点对象 创建文本节点

technical details

DOM version Core Level 1 Document Object


Document Object Reference Document Object