<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.box1 {
width: 100px;
height: 100px;
float: left;
background-color: pink;
}
.box2 {
width: 300px;
height: 300px;
background-color: yellow;
}
</style>
</head>
<body>
<div class="box2">
box2
<div class="box1">box1</div>
</div>
<script>
var box1 = document.getElementsByClassName("box1")[0];
var box2 = document.getElementsByClassName("box2")[0];
box1.addEventListener("click", function (event) {
alert("box1");
var event = event || window.event;
if(event && event.stopPropagation){
event.stopPropagation();
}else{
event.cancelBubble = true;
}
})
box2.addEventListener("click", function () {
alert("box2");
})
document.addEventListener("click", function () {
alert("document");
})
</script>
</body>
</html>