mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Make sure that no extra whitespace is leftover after an addClass. Fixes #6050.
This commit is contained in:
parent
94d925cd46
commit
83a044f1b5
@ -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] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user