Last active
December 23, 2017 13:20
-
-
Save imvsharma/566789f7d808807ebefc6f2d75a903c3 to your computer and use it in GitHub Desktop.
Event Bubbling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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