Bug Tracker

Opened 14 years ago

Closed 14 years ago

#3538 closed bug (fixed)

.unbind() on multiple event types only unbinds first type

Reported by: JonBob Owned by: flesler
Priority: major Milestone: 1.3
Component: event Version: 1.2.6
Keywords: unbind Cc: JonBob, kswedberg
Blocked by: Blocking:


Observed in Firefox 3 Mac.

According to the source code comments for .remove(): // Handle multiple events seperated by a space // jQuery(...).unbind("mouseover mouseout", fn);

This does not appear to actually work; the second event type supplied does nothing. Steps to reproduce in Firebug:

Environment: any page with a visible element (we'll call it <div id="test"></div>) and jQuery loaded.

$('#test').click(function() { console.log('click'); }); $('#test').dblclick(function() { console.log('dblclick'); });

Now clicks and double-clicks will log the appropriate messages.

$('#test').unbind('click dblclick');

Clicks no longer log messages; double-clicks incorrectly do, though.

Change History (3)

comment:1 Changed 14 years ago by JonBob

Okay, here's the problem.

Line 1941 of jquery.js:

for ( handler in events[type] )

The variable handler is being reused here. Not a problem if the loop is only executed once, but if there's a second pass through, this clobbers the parameter handler and causes the other unbinds to fail.

comment:2 Changed 14 years ago by flesler

Cc: JonBob kswedberg added
need: ReviewPatch
Owner: changed from brandon to flesler
Priority: minormajor
Status: newassigned

Will fix this asap.

comment:3 Changed 14 years ago by flesler

Resolution: fixed
Status: assignedclosed

Fixed at [6068]. Refactored unbind tests at [6069], including one for this issue.

Note: See TracTickets for help on using tickets.