<!DOCTYPE HTML>
<html>
<body>
<style type="text/css">
#a {background-color:blue;width:100px;height:200px;}
#b {background-color:red;margin-left:25px;width:50px;height:100px;}
</style>
<div id="a">a
<div id="b">b</div>
</div>
<script>
document.getElementById("a").onclick = function() {console.log("A is clicked");}
document.getElementById("b").onclick = function(event) {console.log("B is clicked");}
document.onclick = function() {console.log("Document is clicked");}
</script>
</body>
</html>
Above code is the demonstration of events bubbling.
Questions:
1.I know bubbling and capturing are two opposite phases. Can I understand this way? the nature of events is bubbling.
2.I did not see too many capturing examples online, so If I want to change above codes to events capturing, how to change?