Created
November 12, 2024 12:13
-
-
Save k0pernikus/c03143806b319e8c3acc5215e4c106de to your computer and use it in GitHub Desktop.
custom event in do not bubble by default, one has to set bubbles true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const customEventHandling = () => { | |
document.addEventListener('this-is-my-custom-event', (event) => { | |
console.log('THIS SHOULD PRINT ON DISPATCHED EVENT!'); | |
console.log(event) | |
}); | |
document.onreadystatechange = () => { | |
if (document.readyState !== "complete") { | |
console.log('not ready yet'); | |
return; | |
} | |
console.log('before dispatch'); | |
const event = new Event('this-is-my-custom-event', {bubbles: true}); | |
const element = document.querySelector('body'); | |
console.log('event i want to dispatch', event); | |
console.log('element i dispatch the event on', element); | |
element.dispatchEvent(event); | |
console.log('after dispatch'); | |
}; | |
} | |
customEventHandling(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment