Skip to content

Commit fa92ce1

Browse files
committed
adding script wesbos#25
1 parent 220254c commit fa92ce1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,24 @@
3939

4040
<button></button>
4141
<script>
42+
const divs = document.querySelectorAll('div');
43+
const button = document.querySelector('button');
4244

45+
function logText(e){
46+
console.log(this.classList.value);
47+
// e.stopPropagation() // stops bubbling
48+
}
49+
50+
divs.forEach(div => div.addEventListener('click', logText,{
51+
capture:false,
52+
once: true
53+
}));
54+
55+
button.addEventListener('click', () => {
56+
console.log('click');
57+
}, {
58+
once: true // removes an event after carried out
59+
});
4360
</script>
4461
</body>
4562
</html>

0 commit comments

Comments
 (0)