10-07-2020 10:47
10-07-2020 10:47
Is it possible to create a custom event and catch it? I tried the code below and the event doesn't seem to get fired.
let event = new Event("hello");
document.body.dispatchEvent(event);
...
document.addEventListener("hello", () => {
console.log("CAUGHT EVENT");
});
11-16-2020 05:59
11-16-2020 05:59
Yes, it should be possible to use dispatchEvent. There's no body element though.
11-29-2022 00:46
11-29-2022 00:46
Can you provide a minimal example of custom events please?