Make jQuery().off(event) work for delegated events.

Logic to handle detaching by event was in both .off() and jQuery.event.remove; now it's only in .off(). It's a bit of a strange case since the event object (not the jQuery set) specifies the element.
This commit is contained in:
Dave Methvin
2011-10-23 22:25:13 -04:00
parent b208042f52
commit 4ac6f8d9d3
2 changed files with 25 additions and 11 deletions

View File

@@ -2054,6 +2054,20 @@ test(".delegate()/.undelegate()", function() {
jQuery("#body").undelegate("#nothiddendiv div", "click");
});
test("jQuery.off using dispatched jQuery.Event", function() {
expect(1);
var markup = jQuery( '<p><a href="#">target</a></p>' ),
count = 0;
markup
.on( "click.name", "a", function( event ) {
equals( ++count, 1, "event called once before removal" );
jQuery().off( event );
})
.find( "a" ).click().click().end()
.remove();
});
test("stopPropagation() stops directly-bound events on delegated target", function() {
expect(1);