Added in #690, the ability to remove an event handler from inside itself.

This commit is contained in:
John Resig 2006-12-23 17:41:00 +00:00
parent c20924818c
commit baa44a8f27
2 changed files with 20 additions and 1 deletions

View File

@ -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();
});

View File

@ -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();