Skip to main content

Bug Tracker

Side navigation

#8568 closed bug (invalid)

Opened March 19, 2011 02:05PM UTC

Closed April 14, 2011 08:05AM UTC

Last modified March 14, 2012 06:56PM UTC

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:
Description

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];

After:

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

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

Changed March 19, 2011 02:07PM UTC by edlebert comment:1

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.

Changed March 20, 2011 09:51PM UTC by dmethvin comment:2

owner: → 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.

Changed March 30, 2011 08:06PM UTC by rwaldron comment:3

component: unfiledevent

Changed April 14, 2011 08:05AM UTC by trac-o-bot comment:4

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!