Skip to main content

Bug Tracker

Side navigation

#10821 closed bug (fixed)

Opened November 17, 2011 08:04PM UTC

Closed November 17, 2011 10:42PM UTC

JQuery.event.add can add handlers for the same event multiple times

Reported by: Owned by:
Priority: undecided Milestone: None
Component: event Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:

This bug identifies a change in behaviour between 1.3.2 and 1.6.4. The change appears to have been introduced with this refactoring:

Prior to this refactoring, the handlers array was defined as an object, and handlers were added to this array keyed on the guid:

handlers = events[ type ] = {};


handlers[ handler.guid ] = handler;

Subsequent to the change:

handlers = events[ type ] = [];


handlers.push( handleObj );

Obviously the first method has the effect of ensuring that the same event will not ever be added twice to the handlers list.

Attachments (0)
Change History (6)

Changed November 17, 2011 08:06PM UTC by comment:1

Here is a minimal page for replicating the issue:

<!DOCTYPE html>



<title>Untitled Page</title>

<script src="//" type="text/javascript"></script>





function clickit()









when you click the li, you will see that the alert appears only one time.

If you change the jquery include to 1.6.4 or 1.7.0, then it will appear two times.

Changed November 17, 2011 08:48PM UTC by rwaldron comment:2

component: unfiledevent
owner: →
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists. To get you started, use this boilerplate:

Open the link and click to "Fork" (in the top menu) to get started.

Changed November 17, 2011 09:06PM UTC by dmethvin comment:3

It's documented at :

The same event handler can be bound to an element multiple times. This is especially useful when the feature is being used, or when other unique data resides in a closure around the event handler function. For example:
 function greet(event) { alert("Hello "; }
$("button").on("click", { name: "Karl" }, greet);
$("button").on("click", { name: "Addy" }, greet);
The above code will generate two different alerts when the button is clicked.

The only action item I see is to document that this changed as of 1.4, but that was almost two years ago.

Changed November 17, 2011 09:09PM UTC by Gwyn Judd <> comment:4

I have updated the jsFiddle link you provided with working test code (I think). I haven't used jsFiddle before so my apologies if I did something incorrect.

The new link should be:

Changed November 17, 2011 09:13PM UTC by Gwyn Judd <> comment:5

Replying to [comment:3 dmethvin]:

The only action item I see is to document that this changed as of 1.4, but that was almost two years ago.

As a user, I hope you will do so - knowing about changes in behaviour from release to release is extremely high priority. I want to keep my code base up to date with later releases, but the risk of finding unexpected defects can prevent us from doing so.

Changed November 17, 2011 10:42PM UTC by dmethvin comment:6

resolution: → fixed
status: pendingclosed

Documentation updated.