Skip to content

Commit e475959

Browse files
committed
add challenge 25
1 parent c6e190b commit e475959

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

  • 25 - Event Capture, Propagation, Bubbling and Once
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
9+
<div class="one">
10+
<div class="two">
11+
<div class="three">
12+
</div>
13+
</div>
14+
</div>
15+
16+
<style>
17+
html {
18+
box-sizing: border-box;
19+
}
20+
21+
*, *:before, *: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 class="button"></button>
44+
<script>
45+
let divs = document.querySelectorAll('div');
46+
let button = document.querySelector('button');
47+
divs.forEach(div => div.addEventListener('click', logText, {
48+
once: false,
49+
capture: true
50+
})
51+
);
52+
53+
button.addEventListener('click',logText,{
54+
once: true
55+
});
56+
57+
function logText(e) {
58+
console.log(this.classList.value);
59+
e.stopPropagation();
60+
}
61+
</script>
62+
</body>
63+
</html>

0 commit comments

Comments
 (0)