-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay67bubblingandcapturing.html
53 lines (47 loc) · 1.46 KB
/
Day67bubblingandcapturing.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
49
50
51
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Day 67</title>
<style>
div{
min-width: 10px;
min-height: 10px;
border: 1px solid black;
padding: 20px;
}
</style>
</head>
<body>
<div id="grantparent">
<div id="parent">
<div id="child">
</div>
</div>
</div>
<script>
//bubbling
document.querySelector('#grantparent').addEventListener('click',()=>{
console.log('grandparent called');//called last
})
document.querySelector('#parent').addEventListener('click',()=>{
console.log('parent called');//called second
})
document.querySelector('#child').addEventListener('click',()=>{
console.log('child called');//called first
})
//capturing
document.querySelector('#grantparent').addEventListener('click',()=>{
console.log('grandparent called');//called first
},true)
document.querySelector('#parent').addEventListener('click',(event)=>{
console.log('parent called');//called second
event.stopPropagation();// this will stop the capturing
},true)
document.querySelector('#child').addEventListener('click',()=>{
console.log('child called');//called last
},true)
</script>
</body>
</html>