Bug Tracker

Ticket #3538 (closed bug: fixed)

Opened 6 years ago

Last modified 6 years ago

.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
Blocking: Blocked by:


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

comment:1 Changed 6 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 6 years ago by flesler

  • Cc JonBob, kswedberg added
  • need changed from Review to Patch
  • Status changed from new to assigned
  • Owner changed from brandon to flesler
  • Priority changed from minor to major

Will fix this asap.

comment:3 Changed 6 years ago by flesler

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Note: See TracTickets for help on using tickets.