Jagajit Prusty Jagajit Prusty -3 years ago 120
Javascript Question

What will be order of execution if I am attaching two same event on a DOM

If I am attaching two click events on an element then what will be order of execution of the two handler. I know the order of execution for

is the same as the order in which the events were attached. But I am not sure about the behaviour with JavaScript.

If it just appends the events handler then if I want to override all existing events handler how can I do?

Answer Source

The handlers will execute in the order in which they were bound.

The DOM3 event spec, introduces the requirement that they be fired in order of registration (what most browsers do):

Next, the implementation must determine the current target's candidate event listeners. This must be the list of all event listeners that have been registered on the current target in their order of registration.

From developer.mozilla.org

Events in the target phase will trigger all listeners on an element in the order they were registered, regardless of the useCapture parameter.-

In addition: Javascript event order

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download