Document createTextNode() Method - Javascript DOM

Javascript examples for DOM:Document createTextNode

Description

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

Parameter Values

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

Return Value:

A Text Node object with the created Text Node

The following code shows how to Create a text node:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from w  ww  .  j a va 2  s. com
    var h = document.createElement("H1");
    var t = document.createTextNode("Hello World");
    h.appendChild(t);
    document.body.appendChild(h);
}
</script>

</body>
</html>

Related Tutorials