jQuery Event How to - Handle click event on inner element








Question

We would like to know how to handle click event on inner element.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from   www  .ja v a2  s .  com-->
    $('.clickable').click(function() {
       console.log('Hello');
    });
    $('a').click(function(event) {
        event.stopPropagation();
    });
});
</script>
</head>
<body>
  <div class="clickable">
    some text... <a href="">Link 1</a> <a href="">Link 2</a>
    some text...
  </div>
</body>
</html>

The code above is rendered as follows: