Skip to content

Commit 174bae4

Browse files
committed
Play around with event propagation
1 parent dc9dd60 commit 174bae4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title></title>
6+
<style>
7+
* {
8+
box-sizing: border-box;
9+
}
10+
html,
11+
body {
12+
height: 100%;
13+
margin: 0;
14+
}
15+
div {
16+
height: 100%;
17+
padding: 50px;
18+
}
19+
div.one {
20+
background-color: #555;
21+
}
22+
div.two {
23+
background-color: #888;
24+
}
25+
div.three {
26+
background-color: #cacaca;
27+
}
28+
</style>
29+
</head>
30+
<body>
31+
<div class="one">
32+
<div class="two">
33+
<div class="three"></div>
34+
</div>
35+
</div>
36+
<script>
37+
function handleClick(e) {
38+
console.log(e.currentTarget);
39+
e.stopPropagation();
40+
}
41+
42+
document.querySelectorAll("div").forEach((div) => {
43+
div.addEventListener("click", handleClick, {
44+
capture: true,
45+
});
46+
});
47+
</script>
48+
</body>
49+
</html>

index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
22. [Follow Along Link Highlighter](https://vais.github.io/JavaScript30/22 - Follow Along Link Highlighter/index.html)
2525
23. [Speech Synthesis](https://vais.github.io/JavaScript30/23 - Speech Synthesis/index.html)
2626
24. [Sticky Nav](https://vais.github.io/JavaScript30/24 - Sticky Nav/index.html)
27+
25. [Event Capture, Propagation, Bubbling and Once](https://vais.github.io/JavaScript30/25 - Event Capture, Propagation, Bubbling and Once/index.html)

0 commit comments

Comments
 (0)