How to determine the order of the event handler in javascript or jquery?

If several event handlers will respond to one event, and the event handler callback function is defined in different places, how can I determine which handler will be launched first, for example, when checking on/off a radio , radio links several handlers, so how to determine which one will be executed first?

+4
source share
2 answers

Javascript event handler order

If you use jQuery to bind your events, this ensures that the handlers fired in the same order that they were bound. Otherwise, the order is officially undefined.

If you cannot use jQuery or a similar structure, you can easily simulate this using your own binding, in which the generic handler is a function that stores an array of functions and calls them in order.

+1
source

Documentation -
All handlers associated with this type of event for an element are triggered. If multiple handlers are registered, they will always be executed in the order in which they were connected. After all handlers are executed, the event continues along the path of propagation of the normal event.

0
source

Source: https://habr.com/ru/post/1379446/


All Articles