Get the id of the wrapping element onclick - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:wrap

Description

Get the id of the wrapping element onclick

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-2.0.0.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from  w w  w . j  av  a2s  .  c om
$('p, span').on('click', function(){
   console.log($(this).attr('id'));
    return false;
});
    });

      </script> 
 </head> 
 <body> 
  <p id="wrapper"> Hello <span id="one"> how </span> are <span id="two">you</span> </p>  
 </body>
</html>

Related Tutorials