Last active
August 29, 2015 14:28
-
-
Save marcojetson/e8daa5e57cb06db4e0aa to your computer and use it in GitHub Desktop.
Add regex support to jQuery's removeClass
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 ($) { | |
'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