},
addClass: function( value ) {
- var classNames, i, l, elem, setClass, c, cl;
+ var classNames, i, l, elem,
+ setClass, c, cl;
if ( jQuery.isFunction( value ) ) {
return this.each(function( j ) {
- var self = jQuery( this );
- self.addClass( value.call(this, j, self.attr("class") || "") );
+ jQuery( this ).addClass( value.call(this, j, this.className) );
});
}
elem.className = value;
} else {
- setClass = elem.className;
+ setClass = " " + elem.className + " ";
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
- if ( !~setClass.indexOf(classNames[ c ]) ) {
- setClass += " " + classNames[ c ];
+ if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
+ setClass += classNames[ c ] + " ";
}
}
elem.className = jQuery.trim( setClass );
if ( jQuery.isFunction( value ) ) {
return this.each(function( j ) {
- var self = jQuery( this );
- self.removeClass( value.call(this, j, self.attr("class")) );
+ jQuery( this ).removeClass( value.call(this, j, this.className) );
});
}
isBool = typeof stateVal === "boolean";
if ( jQuery.isFunction( value ) ) {
- return this.each(function(i) {
- var self = jQuery(this);
- self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );
+ return this.each(function( i ) {
+ jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
});
}
});
var testAddClass = function(valueObj) {
- expect(7);
+ expect(9);
+
var div = jQuery("div");
div.addClass( valueObj("test") );
var pass = true;
div.addClass( valueObj("bar baz") );
equals( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." );
- div.removeAttr("class");
+ div.removeClass();
div.addClass( valueObj("foo") ).addClass( valueObj("foo") )
equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." );
- div.removeAttr("class");
+
+ div.addClass( valueObj("fo") );
+ equal( div.attr("class"), "foo fo", "Adding a similar class does not get interrupted." );
+ div.removeClass().addClass("wrap2");
+ ok( div.addClass("wrap").hasClass("wrap"), "Can add similarly named classes");
+
+ div.removeClass();
div.addClass( valueObj("bar bar") );
equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." );
};
test("toggleClass(Fucntion[, boolean]) with incoming value", function() {
expect(14);
- var e = jQuery("#firstp"), old = e.attr("class");
+ var e = jQuery("#firstp"), old = e.attr("class") || "";
ok( !e.is(".test"), "Assert class not present" );
e.toggleClass(function(i, val) {