Use addEventListener to add event handler to click action - Javascript DOM

Javascript examples for DOM:Element addEventListener

Description

Use addEventListener to add event handler to click action

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(){/*from   w ww.  j  a  v  a  2  s . c o m*/
document
    .getElementById('clickme')
    .addEventListener('click', function() { console.log('attached'); });
    }

      </script> 
   </head> 
   <body> 
      <div onclick="console.log('inline');" id="clickme">
         Click me
      </div>  
   </body>
</html>

Related Tutorials