Javascript examples for DOM:Document createTextNode
The createTextNode() method creates a Text Node with the specified text.
Parameter | Type | Description |
---|---|---|
text | String | Required. The text of the Text node |
A Text Node object with the created Text Node
The following code shows how to Create a text node:
<!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>