Skip to content

Commit 1d8bf0a

Browse files
committed
Fix #12203. .undelegate() should not remove direcly bound events.
1 parent 37e8b44 commit 1d8bf0a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ jQuery.fn.extend({
973973
},
974974
undelegate: function( selector, types, fn ) {
975975
// ( namespace ) or ( selector, types [, fn] )
976-
return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn );
976+
return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
977977
},
978978

979979
trigger: function( type, data ) {

test/unit/event.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,18 +2376,24 @@ test("stopPropagation() stops directly-bound events on delegated target", functi
23762376
});
23772377

23782378
test("undelegate all bound events", function(){
2379-
expect(1);
2379+
expect(2);
23802380

2381-
var count = 0;
2382-
var div = jQuery("#body");
2381+
var count = 0,
2382+
clicks = 0,
2383+
div = jQuery("#body");
23832384

2384-
div.delegate("div#nothiddendivchild", "click submit", function(){ count++; });
2385+
div.delegate( "div#nothiddendivchild", "click submit", function(){ count++; } );
2386+
div.bind( "click", function(){ clicks++; } );
23852387
div.undelegate();
23862388

23872389
jQuery("div#nothiddendivchild").trigger("click");
23882390
jQuery("div#nothiddendivchild").trigger("submit");
23892391

23902392
equal( count, 0, "Make sure no events were triggered." );
2393+
2394+
div.trigger("click");
2395+
equal( clicks, 2, "Make sure delegated and directly bound event occurred." );
2396+
div.unbind("click");
23912397
});
23922398

23932399
test("delegate with multiple events", function(){

0 commit comments

Comments
 (0)