Make a button that will print out more text every click - Javascript DOM

Javascript examples for DOM:Document createTextNode

Description

Make a button that will print out more text every click

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script>
function myFunction()/*w  w w.j  a  va  2s.c o  m*/
{
var h=document.createElement("p");
var t=document.createTextNode("Hello World");
h.appendChild(t);
document.body.appendChild(h);
}

      </script> 
      <p id="demo">Click the button to make more text within a "p" tag.</p> 
      <button onclick="myFunction()">Try it</button>  
   </body>
</html>

Related Tutorials