diff options
author | Rick Waldron <waldron.rick@gmail.com> | 2012-06-23 19:38:27 -0400 |
---|---|---|
committer | Rick Waldron <waldron.rick@gmail.com> | 2012-06-23 19:38:27 -0400 |
commit | 3206be877250f5fe958a0519ef19d52e277687ca (patch) | |
tree | 901fb55ca20104137e90413bcbe376905388dd92 /src/attributes.js | |
parent | 4df3aaeab3f5c1f54d7564fe9973f6bf35664265 (diff) | |
download | jquery-3206be877250f5fe958a0519ef19d52e277687ca.tar.gz jquery-3206be877250f5fe958a0519ef19d52e277687ca.zip |
Make removeClass smart enough to remove duplicates. Fixes #11923
Diffstat (limited to 'src/attributes.js')
-rw-r--r-- | src/attributes.js | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/attributes.js b/src/attributes.js index 23a4fddd0..6ec1c7154 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -71,31 +71,30 @@ jQuery.fn.extend({ }, removeClass: function( value ) { - var classNames, i, l, elem, className, c, cl; + var removes, className, elem, c, cl, i, l; if ( jQuery.isFunction( value ) ) { return this.each(function( j ) { jQuery( this ).removeClass( value.call(this, j, this.className) ); }); } - if ( (value && typeof value === "string") || value === undefined ) { - classNames = ( value || "" ).split( core_rspace ); + removes = ( value || "" ).split( core_rspace ); for ( i = 0, l = this.length; i < l; i++ ) { elem = this[ i ]; - if ( elem.nodeType === 1 && elem.className ) { - if ( value ) { - className = (" " + elem.className + " ").replace( rclass, " " ); - for ( c = 0, cl = classNames.length; c < cl; c++ ) { - className = className.replace(" " + classNames[ c ] + " ", " "); - } - elem.className = jQuery.trim( className ); - } else { - elem.className = ""; + className = (" " + elem.className + " ").replace( rclass, " " ); + + // loop over each item in the removal list + for ( c = 0, cl = removes.length; c < cl; c++ ) { + // Remove until there is nothing to remove, + while ( className.indexOf(" " + removes[ c ] + " ") > -1 ) { + className = className.replace( " " + removes[ c ] + " " , " " ); + } } + elem.className = value ? jQuery.trim( className ) : ""; } } } |