Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#8568 closed bug (invalid)

Live Event callbacks can get out of order in Event liveHandler function.

Reported by: edlebert Owned by: edlebert
Priority: undecided Milestone: 1.next
Component: event Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:


VERSION: This bug exists in jQuery 1.5.1 (and older versions). I do not believe this is a regression, it has always existed as long as liveHandler has been around. It is browser independent.

PROBLEM: The callbacks in liveHandler are executed first on the order of the selector match, then on the order of when they were attached. This makes it possible to execute your callbacks in a different order than they were attached. The problem is verifiable here: http://jsfiddle.net/edlebert/thNds/

The fix is VERY easy, just swap the two loops below in the Event::liveHandler function. Before:

	for ( i = 0, l = match.length; i < l; i++ ) {
		close = match[i];

		for ( j = 0; j < live.length; j++ ) {
			handleObj = live[j];


	for ( j = 0; j < live.length; j++ ) {
		handleObj = live[j];

		for ( i = 0, l = match.length; i < l; i++ ) {
			close = match[i];

Change History (4)

comment:1 Changed 12 years ago by edlebert

I created a pull request on github here: https://github.com/jquery/jquery/pull/280. Sorry, I didn't add a unit test because I'm unfamiliar with the unit testing on jQuery. :) But it shouldn't be hard to create one using the super simple jsfiddle entry listed above in the ticket.

comment:2 Changed 12 years ago by dmethvin

Owner: set to edlebert
Status: newpending

In what situations are you depending on the call order of event handlers? In general this is not a good idea; see #3781. Neither jQuery nor the W3C guarantee the order that event handlers will be called.

comment:3 Changed 12 years ago by Rick Waldron

Component: unfiledevent

comment:4 Changed 12 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Note: See TracTickets for help on using tickets.