Was reading the Docs in MDN about addEventListener
. Then I experimented a bit, ended up with the following code:
const inner = document.querySelector('#inner').addEventListener('click',
() => {
console.log('inner');
}, true);
const outer = document.querySelector('#outer').addEventListener('click',
() => {
console.log('outer');
}, true);
<div id="outer">
<div id="inner">click me</div>
</div>
I thought that by setting the third element of addEventListener
to true
it would stop the event propagation and thus would stop the event bubbling of the inner div
.
- How is this not stopping the bubbling?
- How do I manage to stop the bubbling?