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] );
}
}
}
});
var testAddClass = function(valueObj) {
- expect(2);
+ expect(4);
var div = jQuery("div");
div.addClass( valueObj("test") );
var pass = true;
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() {