Last active
January 13, 2017 18:31
-
-
Save ethanhinson/0a0c34f51ea4fdb28004f6d53c09ea1e to your computer and use it in GitHub Desktop.
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> | |
<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