-
Notifications
You must be signed in to change notification settings - Fork 5
/
eventCapture.jade
47 lines (35 loc) · 1.08 KB
/
eventCapture.jade
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
extends base
block vars
- var title = 'Event Capture, Propagation, Bubbling and Once'
block styles
link(rel="stylesheet" type="text/css" href="styles/eventCapture.css")
block body
.one
.two
.three
input(type="checkbox" name="stopPropagation" data-type="stopPropagation")
span Stop Propagation
script(type="text/javascript").
const $divs = document.querySelectorAll('div')
const $stopPropagationButton = document.querySelector('input[data-type="stopPropagation"]')
let propagate;
function logText(e) {
if (propagate) {
console.log(this.classList.value)
e.stopPropagation() // stop bubbling!!
} else
console.log(this.classList.value)
}
function updateHandler() {
switch(this.dataset.type) {
case 'stopPropagation':
if (this.checked) propagate = true
else propagate = false
break;
}
}
$stopPropagationButton.addEventListener('change', updateHandler)
$divs.forEach(div => div.addEventListener('click', logText, {
capture,
once
}))