aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDevin Wilson <dwilson6.github@gmail.com>2016-01-13 21:06:43 -0700
committerTimmy Willison <timmywillisn@gmail.com>2016-01-15 13:48:53 -0500
commitc4d9eac930b86c192b0f96210d88bb7d91e697e1 (patch)
treee89428e325c22b4d02ac78958b3ad4d7a30362d3
parentdf31b88135f94f903c8a887085d30d085a9c62f6 (diff)
downloadjquery-c4d9eac930b86c192b0f96210d88bb7d91e697e1.tar.gz
jquery-c4d9eac930b86c192b0f96210d88bb7d91e697e1.zip
Event: Fix chaining .on() with null handlers
Fixes gh-2812 Close gh-2825
-rw-r--r--src/event.js2
-rw-r--r--test/unit/event.js9
2 files changed, 9 insertions, 2 deletions
diff --git a/src/event.js b/src/event.js
index e9d1053dc..6d60b4c11 100644
--- a/src/event.js
+++ b/src/event.js
@@ -71,7 +71,7 @@ function on( elem, types, selector, data, fn, one ) {
if ( fn === false ) {
fn = returnFalse;
} else if ( !fn ) {
- return this;
+ return elem;
}
if ( one === 1 ) {
diff --git a/test/unit/event.js b/test/unit/event.js
index 6cccb8d1a..04ca615eb 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -6,7 +6,7 @@ QUnit.module( "event", {
} );
QUnit.test( "null or undefined handler", function( assert ) {
- assert.expect( 2 );
+ assert.expect( 4 );
// Supports Fixes bug #7229
try {
@@ -18,6 +18,13 @@ QUnit.test( "null or undefined handler", function( assert ) {
jQuery( "#firstp" ).on( "click", undefined );
assert.ok( true, "Passing an undefined handler will not throw an exception" );
} catch ( e ) {}
+
+ var expectedElem = jQuery( "#firstp" );
+ var actualElem = expectedElem.on( "click", null );
+ assert.equal(actualElem, expectedElem, "Passing a null handler should return the original element");
+
+ actualElem = expectedElem.on( "click", undefined );
+ assert.equal(actualElem, expectedElem, "Passing a null handler should return the original element");
} );
QUnit.test( "on() with non-null,defined data", function( assert ) {