Last active
May 12, 2017 18:03
-
-
Save dougwollison/c7328e87914978d9cf39 to your computer and use it in GitHub Desktop.
Upgraded jQuery.removeClass, handles Regular Expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( 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