Make sure that no extra whitespace is leftover after an addClass. Fixes #6050.

This commit is contained in:
jeresig 2010-02-13 02:18:38 -05:00
parent 94d925cd46
commit 83a044f1b5
2 changed files with 11 additions and 2 deletions

View File

@ -43,7 +43,7 @@ jQuery.fn.extend({
var className = " " + elem.className + " "; var className = " " + elem.className + " ";
for ( var c = 0, cl = classNames.length; c < cl; c++ ) { for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) { if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {
elem.className += " " + classNames[c]; elem.className = jQuery.trim( elem.className + " " + classNames[c] );
} }
} }
} }

View File

@ -435,7 +435,7 @@ test("val(Function) with incoming value", function() {
}); });
var testAddClass = function(valueObj) { var testAddClass = function(valueObj) {
expect(2); expect(4);
var div = jQuery("div"); var div = jQuery("div");
div.addClass( valueObj("test") ); div.addClass( valueObj("test") );
var pass = true; var pass = true;
@ -448,6 +448,15 @@ var testAddClass = function(valueObj) {
var j = jQuery("#nonnodes").contents(); var j = jQuery("#nonnodes").contents();
j.addClass( valueObj("asdf") ); j.addClass( valueObj("asdf") );
ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" ); 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() { test("addClass(String)", function() {