Skip to content

Instantly share code, notes, and snippets.

@marcojetson
Last active August 29, 2015 14:28
Show Gist options
  • Save marcojetson/e8daa5e57cb06db4e0aa to your computer and use it in GitHub Desktop.
Save marcojetson/e8daa5e57cb06db4e0aa to your computer and use it in GitHub Desktop.
Add regex support to jQuery's removeClass
(function ($) {
'use strict';
$.fn.originalRemoveClass = $.fn.removeClass;
$.fn.removeClass = function (arg) {
if (arg instanceof RegExp) {
return this.originalRemoveClass(function (i, css) {
var remove = [];
$.each(css.split(/\s+/), function (i, cls) {
if (cls.match(arg)) {
remove.push(cls);
}
});
return remove.join(' ');
});
}
return this.originalRemoveClass(arg);
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment