4

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?

3

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.