jQuery Event How to - Get event target property








Question

We would like to know how to get event target property.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.0.2.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from w  w w.j av  a 2  s. c  o  m-->
     $(document).ready(function () {
         $("#a").click(function (event) {
             event.stopPropagation();
             if ($(event.target).prop('id') == 'a') {
                 console.log($(event.target).prop('id'));
             }
         });
     });
});
</script>
</head>
<body>
  <div id="a">
    click
    <div id="b">click b hulk</div>
  </div>
</body>
</html>

The code above is rendered as follows: