10-07-2020 10:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-07-2020 10:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


11-16-2020 05:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yes, it should be possible to use dispatchEvent. There's no body element though.

11-29-2022 00:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

11-29-2022 00:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Can you provide a minimal example of custom events please?
