]> source.dussan.org Git - jquery.git/commitdiff
Make sure that no extra whitespace is leftover after an addClass. Fixes #6050.
authorjeresig <jeresig@gmail.com>
Sat, 13 Feb 2010 07:18:38 +0000 (02:18 -0500)
committerjeresig <jeresig@gmail.com>
Sat, 13 Feb 2010 07:18:38 +0000 (02:18 -0500)
src/attributes.js
test/unit/attributes.js

index d217793cce4343f870c958f17b0fac9fc76cc177..3e4c5f21629776a5f4e5bdf33699790c8761483b 100644 (file)
@@ -43,7 +43,7 @@ jQuery.fn.extend({
                                                var className = " " + elem.className + " ";
                                                for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
                                                        if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {
-                                                               elem.className += " " + classNames[c];
+                                                               elem.className = jQuery.trim( elem.className + " " + classNames[c] );
                                                        }
                                                }
                                        }
index 70ae50dbda77870571ab18f213f368060d19e782..234d586220224675da4a9041a5972949eba439af 100644 (file)
@@ -435,7 +435,7 @@ test("val(Function) with incoming value", function() {
 });
 
 var testAddClass = function(valueObj) {
-       expect(2);
+       expect(4);
        var div = jQuery("div");
        div.addClass( valueObj("test") );
        var pass = true;
@@ -448,6 +448,15 @@ var testAddClass = function(valueObj) {
        var j = jQuery("#nonnodes").contents();
        j.addClass( valueObj("asdf") );
        ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
+
+       div = jQuery("<div/>");
+
+       div.addClass( valueObj("test") );
+       equals( div.attr("class"), "test", "Make sure there's no extra whitespace." );
+
+       div.attr("class", " foo");
+       div.addClass( valueObj("test") );
+       equals( div.attr("class"), "foo test", "Make sure there's no extra whitespace." );
 };
 
 test("addClass(String)", function() {