diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index ada71959..67dea206 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -564,3 +564,16 @@ test("removeClass(String) - add three classes and remove again", function() { test("removeAttr(String", function() { ok( $('#mark').removeAttr("class")[0].className == "", "remove class" ); }); + +test("unbind(event)", function() { + expect(3); + var el = $("#firstp"); + el.click(function() { + ok( true, "Fake normal bind" ); + }); + el.click(function(event) { + el.unbind(event); + ok( true, "Fake onebind" ); + }); + el.click().click(); +}); diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index d22d136f..63b6ece9 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -2090,7 +2090,9 @@ jQuery.extend({ // Detach an event or set of events from an element remove: function(element, type, handler) { if (element.events) - if (type && element.events[type]) + if ( type && type.type ) + delete element.events[ type.type ][ type.handler.guid ]; + else if (type && element.events[type]) if ( handler ) delete element.events[type][handler.guid]; else @@ -2135,6 +2137,10 @@ jQuery.extend({ args.unshift( event ); for ( var j in c ) { + // Pass in a reference to the handler function itself + // So that we can later remove it + args[0].handler = c[j]; + if ( c[j].apply( this, args ) === false ) { event.preventDefault(); event.stopPropagation();