views:

83

answers:

3

Does Events Handlers in JavaScript for one event fired as FIFO, LIFO or in parallel?

+2  A: 
CMS
A: 

PPK has an excellent writeup on Event bubbling and Event Capturing.

http://www.quirksmode.org/js/events_order.html

Thiyagaraj
+3  A: 

It's very simple. DOM Level 2 Events module does not specify order in which event listeners are to be fired. However, DOM Level 3 Events module does specify order to be the same as registration one.

First registered — first fired.

Note that DOM Level 3 Events module is still a draft, whereas Level 2 one is a recommendation. Nevertheless, modern browsers often follow semantics of exactly this draft Level 3 specification, instead of an older Level 2 one.

In practice, IIRC, only IE doesn't respect order of event listeners. All other browsers implement it as FIFO (and as described in DOM L3 Events). You can also find related tests online :)

kangax
Nice references.
Crescent Fresh
Indeed I seriously hate IE8 right now because it's executing my events in REVERSE order relative to every other browser on the planet *including* IE7. Grr.
LRE