I often end up with some event bindings firing multiple times in Jquery/Jquery Mobile, especially when using the new Jquery on() vs. Jquery live();
Example:
$(document).on("pagebeforechange", function (e, data) {
// stuff
});
I’m wondering the following:
If I have multiple binds like the above, will they each fire once or will they fire as many times as I’m using the binding.
Example:
3 document/pagebeforechange listeners = every listener 1x
3 document/pagebeforechange listeners = every listener 3x
Thanks for some clarification!
Each call to
.bind(),.on(),.delegate()etc. will create a new, unique event handler and gets queued up.So yes, each call to those methods will fire a new handler. Don’t be sloppy with that.
For instance
This would alert
span #1followed byspan #2when we click on the span.