Get the id of a the item that is clicked - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Get the id of a the item that is clicked

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://code.jquery.com/jquery-1.7.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from w  w  w.  j av  a2 s .  c  o m*/
    $('b.edit').click(function(){
         console.log($(this).attr('id'));
    });
    });

      </script> 
 </head> 
 <body> 
  <b class="edit" id="foo1">FOO</b> 
  <b class="edit" id="foo2">FOO2</b> 
  <b class="edit" id="foo3">FOO3</b>  
 </body>
</html>

Related Tutorials