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-19 12:27:58 -0500
commit17f0e26ad9eba67ab274d12274cf7c23c8c688fd (patch)
treef10ba07dff38ebc535e8d0c299662cdd0984e91e
parent780cac802b32a0125c467a644b3803be378ae6ab (diff)
downloadjquery-17f0e26ad9eba67ab274d12274cf7c23c8c688fd.tar.gz
jquery-17f0e26ad9eba67ab274d12274cf7c23c8c688fd.zip
Event: Fix chaining .on() with null handlers
Fixes gh-2846
-rw-r--r--src/event.js2
-rw-r--r--test/unit/event.js22
2 files changed, 24 insertions, 0 deletions
diff --git a/src/event.js b/src/event.js
index ddd92c5fc..c8a14fe7d 100644
--- a/src/event.js
+++ b/src/event.js
@@ -70,6 +70,8 @@ function on( elem, types, selector, data, fn, one ) {
}
if ( fn === false ) {
fn = returnFalse;
+ } else if ( !fn ) {
+ return elem;
}
if ( one === 1 ) {
diff --git a/test/unit/event.js b/test/unit/event.js
index 4a5611be8..fd7d86f7f 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -5,6 +5,28 @@ QUnit.module( "event", {
teardown: moduleTeardown
} );
+QUnit.test( "null or undefined handler", function( assert ) {
+ assert.expect( 4 );
+
+ // Supports Fixes bug #7229
+ try {
+ jQuery( "#firstp" ).on( "click", null );
+ assert.ok( true, "Passing a null handler will not throw an exception" );
+ } catch ( e ) {}
+
+ try {
+ 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 ) {
assert.expect( 2 );