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

This commit is contained in:
John Resig 2009-01-20 17:33:25 +00:00
parent a78557472c
commit cd28922b78
2 changed files with 7 additions and 3 deletions

View file

@ -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 file

@ -1557,7 +1557,7 @@ test("addClass(String)", function() {
});
test("removeClass(String) - simple", function() {
expect(4);
expect(5);
var $divs = jQuery('div');
@ -1574,6 +1574,10 @@ test("removeClass(String) - simple", function() {
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" );