0

How to write this jQuery code

$(selector).on('click.custom-namespace', function () {...});

into vanilla JavaScript solution? addEventListener don't get events with custom namespace.

Thanks

quarky
  • 710
  • 2
  • 13
  • 36
  • Possible duplicate of [Event Handler Namespace in Vanilla JavaScript](https://stackoverflow.com/questions/21817397/event-handler-namespace-in-vanilla-javascript) – Hitmands Aug 08 '17 at 16:38
  • Possible duplicate of [JavaScript click event listener on class](https://stackoverflow.com/questions/19655189/javascript-click-event-listener-on-class) – Mark Schultheiss Aug 08 '17 at 16:38
  • This takes some additional setup in vanilla JS to do. There are small libraries that help with this sort of thing: For example: [event-bundle](https://github.com/kevinokerlund/event-bundle) – KevBot Aug 08 '17 at 16:40
  • Trigger/fire of custom event might also help you https://stackoverflow.com/questions/7057223/firing-and-capturing-custom-events – Mark Schultheiss Aug 08 '17 at 16:46
  • @Hitmands thanks, I have already read this thread and I also try custom Event class that Andrew mention. But this has one problem and it is if I declare same event name with same namespace to two or more different elements. Other answer was irrelevant. – quarky Aug 08 '17 at 17:45
  • @MarkSchultheiss I don't see any event namespace in that thread. Creating custom events looks great, but I don't know how I can apply something like this click.custom-namespace using this custom event. – quarky Aug 08 '17 at 17:48

0 Answers0