Handle click event without jquery - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Handle click event without jquery

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> 
 </head> /*w  w  w . ja v  a2s .  c om*/
 <body> 
  <div> 
   <a class="link1" style="cursor:pointer;">click me 1</a> 
  </div> 
  <script type="text/javascript">
document.querySelector("a[class*='link']").addEventListener('click',function(ev){
   console.log(JSON.stringify(this.classList[0]));
});

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

Related Tutorials