I'm working with jquery such that many DOM elements have an expando object. These objects need to send events to each other. I would like to use jquery custom events to make a very simple subscription event model. Instead of calling the event generator object to subscribe to an event, one would simply bind a custom jquery event to themselves.
Event subscriber: $(subscriber_element).bind("myEvent", function() { alert("I received an event without subscribing!"); }); Event generator: $(*).trigger("myEvent"); I am concerned though about the performance of $(*). If I understand jquery properly, this would actually build an array of every element in the DOM and then try to send myEvent to each one. Is this correct? It would seem to me that jquery would keep an internal list of the event bindings and there would be a much more efficient way to send an event to only elements that have that event bound to them. I cannot figure out how to do this.