Hi, I’ve got a super basic example of a Custom Element firing a Custom Event, but the listener is never triggered.
Using monitorEvents(window, ‘my-event’) in Chrome Dev Tools I can see the event firing.
Hoping I’m missing something super obvious! Thanks in advance.
// my-custom-element.js
class MyElement extends HTMLElement {
connectedCallback () {
this . innerHTML = ‘Hello World!’ ;
// Trigger an event that Velo can watch for
// and handle using the [`on()`] function.
**this** . dispatchEvent ( **new** CustomEvent ( 'my-event' ));
}
}
customElements . define ( ‘my-custom-element’ , MyElement );
// Page
$w . onReady ( function () {
$w ( ‘#customElement’ ). on ( ‘my-event’ , ( event ) => {
console . log ( “Triggered” ); // This never fires
});
});