]> source.dussan.org Git - jquery.git/commitdiff
Make sure the resulting className from removeClass is nicely trimmed. Fixes #5988.
authorjeresig <jeresig@gmail.com>
Tue, 2 Feb 2010 02:33:58 +0000 (21:33 -0500)
committerjeresig <jeresig@gmail.com>
Tue, 2 Feb 2010 02:33:58 +0000 (21:33 -0500)
src/attributes.js
test/unit/attributes.js

index 82a4de1bd1136afc159eb680f1bde7ff328930f7..b22acba03ec72902cae1f7f1109d45723c478c6c 100644 (file)
@@ -74,7 +74,7 @@ jQuery.fn.extend({
                                                for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
                                                        className = className.replace(" " + classNames[c] + " ", " ");
                                                }
-                                               elem.className = className.substring(1, className.length - 1);
+                                               elem.className = jQuery.trim( className );
 
                                        } else {
                                                elem.className = "";
index fd5b203df5026476ca4e2899409443c59528c18d..70ae50dbda77870571ab18f213f368060d19e782 100644 (file)
@@ -478,7 +478,7 @@ test("addClass(Function) with incoming value", function() {
 });
 
 var testRemoveClass = function(valueObj) {
-       expect(5);
+       expect(7);
 
        var $divs = jQuery('div');
 
@@ -508,6 +508,17 @@ var testRemoveClass = function(valueObj) {
        var j = jQuery("#nonnodes").contents();
        j.removeClass( valueObj("asdf") );
        ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
+
+       var div = document.createElement("div");
+       div.className = " test foo ";
+
+       jQuery(div).removeClass( valueObj("foo") );
+       equals( div.className, "test", "Make sure remaining className is trimmed." );
+
+       div.className = " test ";
+
+       jQuery(div).removeClass( valueObj("test") );
+       equals( div.className, "", "Make sure there is nothing left after everything is removed." );
 };
 
 test("removeClass(String) - simple", function() {