aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/attributes.js')
-rw-r--r--src/attributes.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/attributes.js b/src/attributes.js
index f7525755f..4da2db6c6 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -102,8 +102,11 @@ jQuery.fn.extend({
},
toggleClass: function( value, stateVal ) {
- var type = typeof value,
- isBool = typeof stateVal === "boolean";
+ var type = typeof value;
+
+ if ( typeof stateVal === "boolean" && type === "string" ) {
+ return stateVal ? this.addClass( value ) : this.removeClass( value );
+ }
if ( jQuery.isFunction( value ) ) {
return this.each(function( i ) {
@@ -117,13 +120,15 @@ jQuery.fn.extend({
var className,
i = 0,
self = jQuery( this ),
- state = stateVal,
classNames = value.match( core_rnotwhite ) || [];
while ( (className = classNames[ i++ ]) ) {
// check each className given, space separated list
- state = isBool ? state : !self.hasClass( className );
- self[ state ? "addClass" : "removeClass" ]( className );
+ if ( self.hasClass( className ) ) {
+ self.removeClass( className );
+ } else {
+ self.addClass( className );
+ }
}
// Toggle whole class name