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_eve开发者_如何转开发nt_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.
精彩评论