Javascript examples for DOM:Document createTextNode
Document createTextNode() Method - Create a <p> element with some text:
<!DOCTYPE html> <html> <head> <style> #myDIV {/* w w w .j a va 2 s .co m*/ border: 1px solid black; margin-bottom: 10px; } </style> </head> <body> <div id="myDIV"> A DIV element </div> <button onclick="myFunction()">Test</button> <script> function myFunction() { var para = document.createElement("P"); var t = document.createTextNode("This is a paragraph."); para.appendChild(t); document.getElementById("myDIV").appendChild(para); } </script> </body> </html>