From 227c49a4596423a125bdcb1d25a2263e526360db Mon Sep 17 00:00:00 2001 From: =?utf8?q?Matthias=20J=C3=A4ggli?= Date: Tue, 28 Aug 2012 16:26:06 +0300 Subject: [PATCH] Fix #12411, .removeClass(undefined) is a chaining no-op. Close gh-913. .removeClass() //removes all classes, as documented .removeClass(window.nonExistentVariable) // removes nothing --- src/attributes.js | 2 +- test/unit/attributes.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/attributes.js b/src/attributes.js index 68e763e09..00e21af35 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -78,7 +78,7 @@ jQuery.fn.extend({ jQuery( this ).removeClass( value.call(this, j, this.className) ); }); } - if ( (value && typeof value === "string") || value === undefined ) { + if ( (value && typeof value === "string") || !arguments.length ) { removes = ( value || "" ).split( core_rspace ); for ( i = 0, l = this.length; i < l; i++ ) { diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 9ead9a9b9..0e51ee137 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -1202,6 +1202,15 @@ test( "removeClass() removes duplicates", function() { ok( !$div.hasClass("x"), "Element with multiple same classes does not escape the wrath of removeClass()" ); }); +test("removeClass(undefined) is a no-op", function() { + expect( 1 ); + + var $div = jQuery("
"); + $div.removeClass( undefined ); + + ok( $div.hasClass("base") && $div.hasClass("second"), "Element still has classes after removeClass(undefined)" ); +}); + var testToggleClass = function(valueObj) { expect( 17 ); -- 2.39.5