If more than one event handlers will response to one event, and the event handler callback function is defined in different places, how can i tell which handler will be triggered first, e.g.when checking on/off a radio, the radio binds several handlers, so how to tell which one will be executed first?
-
possible duplicate of Javascript event handler orderJakub Konecki– Jakub Konecki2011-11-03 09:34:20 +00:00Commented Nov 3, 2011 at 9:34
-
See the answer here: stackoverflow.com/questions/2706109/…a'r– a'r2011-11-03 09:36:52 +00:00Commented Nov 3, 2011 at 9:36
-
Does this answer your question? Priority when more than one event handler is bound to an element via JQuerystarball– starball ♦2024-01-23 00:05:01 +00:00Commented Jan 23, 2024 at 0:05
Add a comment
|
2 Answers
Javascript event handler order
If you use JQuery to bind your events, it guarantees that handlers are fired in the same order that they were bound. Otherwise the order is officially undefined.
If you cannot use JQuery or a similar framework you can easily simulate this by using your own custom even binding, where your generic handler is a function which keeps an array of functions and calls them in order.