Skip to content

Commit d658125

Browse files
committed
Finished exercise wesbos#25
1 parent 5e4e6ce commit d658125

File tree

1 file changed

+62
-0
lines changed
  • 25 - Event Capture, Propagation, Bubbling and Once

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Understanding JavaScript's Capture</title>
6+
</head>
7+
<body class="bod">
8+
<div class="one">
9+
<div class="two">
10+
<div class="three"></div>
11+
</div>
12+
</div>
13+
14+
<style>
15+
html {
16+
box-sizing: border-box;
17+
}
18+
19+
*,
20+
*:before,
21+
*:after {
22+
box-sizing: inherit;
23+
}
24+
25+
div {
26+
width: 100%;
27+
padding: 100px;
28+
}
29+
30+
.one {
31+
background: thistle;
32+
}
33+
34+
.two {
35+
background: mistyrose;
36+
}
37+
38+
.three {
39+
background: coral;
40+
}
41+
</style>
42+
43+
<button></button>
44+
<script>
45+
const divs = document.querySelectorAll("div");
46+
47+
function logText(e) {
48+
console.log(this.classList.value);
49+
// e.stopPropagation();
50+
}
51+
52+
document.body.addEventListener("click", logText);
53+
54+
divs.forEach((div) =>
55+
div.addEventListener("click", logText, {
56+
capture: false,
57+
once: true,
58+
})
59+
);
60+
</script>
61+
</body>
62+
</html>

0 commit comments

Comments
 (0)