Skip to content
Permalink
Browse files
Added in #690, the ability to remove an event handler from inside its…
…elf.
  • Loading branch information
jeresig committed Dec 23, 2006
1 parent c209248 commit baa44a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
@@ -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();
});
@@ -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();

0 comments on commit baa44a8

Please sign in to comment.