Skip to content

Instantly share code, notes, and snippets.

@lnfnunes
Last active August 29, 2015 14:17
Show Gist options
  • Save lnfnunes/f6f0d59c0cec9a5e8ce7 to your computer and use it in GitHub Desktop.
Save lnfnunes/f6f0d59c0cec9a5e8ce7 to your computer and use it in GitHub Desktop.
[jQuery] Remove similar classes by wildcard " * "
/**
* @author: ThiefMaster
* @source: https://stackoverflow.com/a/8899812/1946632
**/
(function($) {
$.fn.removeClassSimilar = function(mask) {
return this.removeClass(function(index, cls) {
var re = mask.replace(/\*/g, '\\S+');
return (cls.match(new RegExp('\\b' + re + '', 'g')) || []).join(' ');
});
};
})(jQuery);
$selector.removeClassSimilar('classprefix-*');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment