Skip to content

Instantly share code, notes, and snippets.

@ethanhinson
Last active January 13, 2017 18:31
Show Gist options
  • Save ethanhinson/0a0c34f51ea4fdb28004f6d53c09ea1e to your computer and use it in GitHub Desktop.
Save ethanhinson/0a0c34f51ea4fdb28004f6d53c09ea1e to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Event Bubbling</title>
<script type="text/javascript">
window.onload = function() {
var div1 = document.querySelector("#div1");
var div2 = document.querySelector("#div2");
div1.addEventListener("click", function (event) {
alert("you clicked on div 1");
}, true);
div2.addEventListener("click", function (event) {
alert("you clicked on div 2");
}, false);
};
</script>
<style>
#div1 {
background-color:red;
padding: 24px;
}
#div2 {
background-color:green;
}
</style>
</head>
<body>
<div id="div1">
div 1
<div id="div2">
div 2
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment