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?
Asked
Active
Viewed 213 times
4

thecodeparadox
- 86,271
- 21
- 138
- 164

David
- 2,691
- 7
- 38
- 50
-
possible duplicate of [Javascript event handler order](http://stackoverflow.com/questions/5143817/javascript-event-handler-order) – Jakub Konecki Nov 03 '11 at 09:34
-
See the answer here: http://stackoverflow.com/questions/2706109/are-event-handlers-in-javascript-called-in-order – a'r Nov 03 '11 at 09:36
2 Answers
1
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.

Community
- 1
- 1

Jakub Konecki
- 45,581
- 7
- 87
- 126
0
Documentation -
All handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound. After all handlers have executed, the event continues along the normal event propagation path.

Jayendra
- 52,349
- 4
- 80
- 90