Skip to content

Instantly share code, notes, and snippets.

@dougwollison
Last active May 12, 2017 18:03
Show Gist options
  • Save dougwollison/c7328e87914978d9cf39 to your computer and use it in GitHub Desktop.
Save dougwollison/c7328e87914978d9cf39 to your computer and use it in GitHub Desktop.
Upgraded jQuery.removeClass, handles Regular Expression
( function( $ ) {
// Store the original method for all other uses
var oldRemoveClass = $.fn.removeClass;
// Replace existing method iwth new version
$.fn.removeClass = function( className ) {
if ( className instanceof RegExp ) {
// Run a regex replace on each element's class name list
return $( this ).each( function() {
var classes = $( this ).attr( 'class' ) || '';
classes = classes.replace( className, '' ).trim(); // For excess spaces
$( this ).attr( 'class', classes );
} );
} else {
// Use original method
return oldRemoveClass.apply( this, arguments );
}
};
} )( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment