Skip to content

Commit 4d2e598

Browse files
committed
wesbos#25 capturing
1 parent 995180c commit 4d2e598

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

25 - Event Capture, Propagation, Bubbling and Once/index-START.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,22 @@
4242

4343
<button></button>
4444
<script>
45-
45+
// takeaways
46+
// bubbling basically takes the event and does it on every parent, then the chrome tab, then chrome, then the window.. etc.
47+
// you can do it the other way by using caputuring
48+
// addeventlistener takes three arguements
49+
// 1. the type of event,
50+
// 2. callback
51+
// 3. an options object, with
52+
// capture -> boolean [false] that uses capturing rather than bubbling
53+
// once -> boolean [false] that removes the event handler after its been used
54+
// passive -> boolean [false] if true it will stop any prevent default
55+
document.querySelectorAll('div').forEach(element => {
56+
element.addEventListener('click', (e) => {
57+
e.stopPropagation();
58+
console.dir(element);
59+
}, {once: true})
60+
});
4661
</script>
4762
</body>
4863
</html>

0 commit comments

Comments
 (0)