6 ], function( jQuery, rnotwhite, strundefined ) {
8 var rclass = /[\t\r\n\f]/g;
11 addClass: function( value ) {
12 var classes, elem, cur, clazz, j, finalValue,
15 proceed = typeof value === "string" && value;
17 if ( jQuery.isFunction( value ) ) {
18 return this.each(function( j ) {
19 jQuery( this ).addClass( value.call( this, j, this.className ) );
24 // The disjunction here is for better compressibility (see removeClass)
25 classes = ( value || "" ).match( rnotwhite ) || [];
27 for ( ; i < len; i++ ) {
29 cur = elem.nodeType === 1 && ( elem.className ?
30 ( " " + elem.className + " " ).replace( rclass, " " ) :
36 while ( (clazz = classes[j++]) ) {
37 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
42 // only assign if different to avoid unneeded rendering.
43 finalValue = jQuery.trim( cur );
44 if ( elem.className !== finalValue ) {
45 elem.className = finalValue;
54 removeClass: function( value ) {
55 var classes, elem, cur, clazz, j, finalValue,
58 proceed = arguments.length === 0 || typeof value === "string" && value;
60 if ( jQuery.isFunction( value ) ) {
61 return this.each(function( j ) {
62 jQuery( this ).removeClass( value.call( this, j, this.className ) );
66 classes = ( value || "" ).match( rnotwhite ) || [];
68 for ( ; i < len; i++ ) {
70 // This expression is here for better compressibility (see addClass)
71 cur = elem.nodeType === 1 && ( elem.className ?
72 ( " " + elem.className + " " ).replace( rclass, " " ) :
78 while ( (clazz = classes[j++]) ) {
79 // Remove *all* instances
80 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
81 cur = cur.replace( " " + clazz + " ", " " );
85 // only assign if different to avoid unneeded rendering.
86 finalValue = value ? jQuery.trim( cur ) : "";
87 if ( elem.className !== finalValue ) {
88 elem.className = finalValue;
97 toggleClass: function( value, stateVal ) {
98 var type = typeof value;
100 if ( typeof stateVal === "boolean" && type === "string" ) {
101 return stateVal ? this.addClass( value ) : this.removeClass( value );
104 if ( jQuery.isFunction( value ) ) {
105 return this.each(function( i ) {
106 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
110 return this.each(function() {
111 if ( type === "string" ) {
112 // toggle individual class names
115 self = jQuery( this ),
116 classNames = value.match( rnotwhite ) || [];
118 while ( (className = classNames[ i++ ]) ) {
119 // check each className given, space separated list
120 if ( self.hasClass( className ) ) {
121 self.removeClass( className );
123 self.addClass( className );
127 // Toggle whole class name
128 } else if ( type === strundefined || type === "boolean" ) {
129 if ( this.className ) {
130 // store className if set
131 jQuery._data( this, "__className__", this.className );
134 // If the element has a class name or if we're passed "false",
135 // then remove the whole classname (if there was one, the above saved it).
136 // Otherwise bring back whatever was previously saved (if anything),
137 // falling back to the empty string if nothing was stored.
138 this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || "";
143 hasClass: function( selector ) {
144 var className = " " + selector + " ",
147 for ( ; i < l; i++ ) {
148 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {