-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventbubbling.html
48 lines (47 loc) · 972 Bytes
/
eventbubbling.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<title>Event Bubbling</title>
<style>
body{
padding:20px;
background-color:pink;
}
div{
padding:20px;
background-color:green;
width:max-content;
}
span{
display:block;
padding:20px;
background-color:blue;
}
</style>
</head>
<body>
<div>
<span>
<button>Click Me!</button>
</span>
</div>
<script>
const body=document.getElementsByTagName("body")[0];
const div=document.getElementsByTagName("div")[0];
const span=document.getElementsByTagName("span")[0];
const button=document.getElementsByTagName("button")[0];
body.addEventListener('click',()=>{
console.log("body is clicked");
});
div.addEventListener('click',()=>{
console.log("div is clicked");
});
span.addEventListener('click',()=>{
console.log("span is clicked");
});
button.addEventListener('click',()=>{
console.log("button is clicked");
});
</script>
</body>
</html>