I have a custom event I've made which I would like to trigger at some point with no relevance to selection.
I.E - I would like to do something that would behave as running
$("*").trigger('customEvent');
But jQuery documentation warns that using the universal selector is very slow.
Is there a way to trigger all the object that are bound to a specific event without having to use the universal selector $("*")
?
Thanks!
P.S - I'm currently using a specific class
called custom_event_listener
and use $('.custom_event_listener').trigger('customEvent')
to avoid using a universal selector. I'm wondering if there is a way to avoid the use of a class
.
You can trigger an event on everything that has a handler bound like this:
$.event.trigger('customEvent');
This loops through $.cache
to find what actually has a handler, then fires on those elements...rather than just finding every element and firing the event on each one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With