Skip to content
Permalink
Browse files
Make sure that no extra whitespace is leftover after an addClass. Fix…
…es #6050.
  • Loading branch information
jeresig committed Feb 13, 2010
1 parent 94d925c commit 83a044f1b5a733dc7ea76dbc9b7dd3a3dc4b7f25
Showing 2 changed files with 11 additions and 2 deletions.
@@ -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] );
}
}
}
@@ -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() {

3 comments on commit 83a044f

@leeoniya
Copy link

@leeoniya leeoniya commented on 83a044f Feb 13, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it make sense to run trim just once after the entire for loop rather than each time?

@leeoniya
Copy link

@leeoniya leeoniya commented on 83a044f Feb 13, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...same with removeClass?

@jeresig
Copy link
Member Author

@jeresig jeresig commented on 83a044f Feb 13, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removeClass already does it after it's all done. Fixed addClass though, thanks for the heads-up: 437ddb9.

Please sign in to comment.