Create button element and its content as text node - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Create button element and its content as text node

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body onload="createButton()">   
      <script>
function createButton(){/*ww w  .java  2 s .  c o  m*/
var newButton = document.createElement("button");
newButton.onclick = function() { 
  document.write('test') 
};
var textButton = document.createTextNode("new Node");
newButton.appendChild(textButton);
document.body.appendChild(newButton);
}

      </script>      
   </body>
</html>

Related Tutorials