Permalink
Browse files

Made sure that .removeClass(null) doesn't throw an exception. Fixes #…

…3847.
  • Loading branch information...
1 parent a785574 commit cd28922b78a91c530c509638294fe3fac9c361f3 @jeresig jeresig committed Jan 20, 2009
Showing with 7 additions and 3 deletions.
  1. +1 −1 src/core.js
  2. +6 −2 test/unit/core.js
View
2 src/core.js
@@ -708,7 +708,7 @@ jQuery.extend({
// internal only, use hasClass("class")
has: function( elem, className ) {
- return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
+ return elem && jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
}
},
View
8 test/unit/core.js
@@ -1557,7 +1557,7 @@ test("addClass(String)", function() {
});
test("removeClass(String) - simple", function() {
- expect(4);
+ expect(5);
var $divs = jQuery('div');
@@ -1566,13 +1566,17 @@ test("removeClass(String) - simple", function() {
ok( !$divs.is('.test'), "Remove Class" );
reset();
-
+
$divs.addClass("test").addClass("foo").addClass("bar");
$divs.removeClass("test").removeClass("bar").removeClass("foo");
ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" );
reset();
+
+ // Make sure that a null value doesn't cause problems
+ $divs.eq(0).addClass("test").removeClass(null);
+ ok( $divs.eq(0).is('.test'), "Null value passed to removeClass" );
$divs.eq(0).addClass("test").removeClass("");
ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" );

0 comments on commit cd28922

Please sign in to comment.