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 baa44a8f2731ec48f5f1b2349db2f956b7173635
Showing with 20 additions and 1 deletion.
  1. +13 −0 src/jquery/coreTest.js
  2. +7 −1 src/jquery/jquery.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();
});
@@ -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.