Skip to content

Instantly share code, notes, and snippets.

@unijad
Created April 2, 2014 10:46
Show Gist options
  • Save unijad/9931802 to your computer and use it in GitHub Desktop.
Save unijad/9931802 to your computer and use it in GitHub Desktop.
.parent {padding:25px; border:1px solid #ccc; background:#ccc;}
.child {background:#fff; padding:15px; margin:5px 0 0;}
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="parent">
parent
<div class="child">child</div>
</div>
</body>
</html>
$('.parent').on('click', function(e){
console.log($(e.target).hasClass('child'));
if($(e.target).hasClass('child')) {
alert('child');
} else {
alert('parent');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment