-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstop-propogation.html
38 lines (38 loc) · 997 Bytes
/
stop-propogation.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stop propagation</title>
</head>
<body>
<div
id="green"
style="background-color: green; width: 150px; height: 150px"
>
<div
id="blue"
style="background-color: blue; width: 100px; height: 100px"
>
<div
id="red"
style="background-color: red; width: 50px; height: 50px"
></div>
</div>
</div>
<script>
document.querySelector('#green').addEventListener('click', function () {
console.log('green')
})
document.querySelector('#blue').addEventListener('click', function () {
console.log('blue')
})
document
.querySelector('#red')
.addEventListener('click', function (event) {
event.stopPropagation()
console.log('red')
})
</script>
</body>
</html>