jQuery Event How to - Check event triggering element id








Question

We would like to know how to check event triggering element id.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.3.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from   ww w  . jav a2s.  c o  m-->
    $('#outer').click(function(e) {
        if (e.target.id === "outer"){
            $('#outer').fadeOut();
        }        
    });
});
</script>
</head>
<body>
  <div id="outer">
    out
    <div id="inner">inside</div>
  </div>
</body>
</html>

The code above is rendered as follows: