Add click event handler to element with addEventListener() - Javascript DOM

Javascript examples for DOM:Element addEventListener

Description

Add click event handler to element with addEventListener()

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body>  
      <button id="myButton" type="button">Submit</button>  
      <script>
    function addToList() {/* ww  w  . j  a va 2 s .  co m*/
        console.log("addToList() function called !!!");
    }
    document.getElementById("myButton").addEventListener("click", addToList);

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

Related Tutorials