Skip to content

Instantly share code, notes, and snippets.

@imvsharma
Last active December 23, 2017 13:20
Show Gist options
  • Save imvsharma/566789f7d808807ebefc6f2d75a903c3 to your computer and use it in GitHub Desktop.
Save imvsharma/566789f7d808807ebefc6f2d75a903c3 to your computer and use it in GitHub Desktop.
Event Bubbling
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Event Bubbling</title>
</head>
<body>
<div id="parent">
<button id="child">Child</button>
</div>
<script>
var parent = document.querySelector('#parent');
<!-- Add click event on parent div -->
parent.addEventListener('click', function(){
console.log("Parent clicked");
});
var child = document.querySelector('#child');
<!-- Add click event on child button -->
child.addEventListener('click', function(){
console.log("Child clicked");
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment