Click event attach to button - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Click event attach to button

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {// w  ww  . jav  a2  s .co m
var widget = document.getElementById("widget");
widget.innerHTML = '<button id="mahbutton">Clicky</button>';
var w_btn = document.getElementById("mahbutton");
w_btn.addEventListener("click",
    function() {
        console.log("sdf");
    }
);
    });

      </script> 
   </head> 
   <body> 
      <div id="widget"> 
      </div>  
   </body>
</html>

Related Tutorials