Create a text node:
var t = document.createTextNode("Hello World");
Click the button to create a Text Node.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/* w ww . jav a 2s . co m*/ var t = document.createTextNode("Hello World"); document.body.appendChild(t); } </script> </body> </html>
HTML elements often consists of both an element node and a text node.
To create a header (e.g. <h1>), you must create both an <h1> element and a text node: