Skip to content

Instantly share code, notes, and snippets.

@nkohari
Created October 28, 2010 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkohari/650532 to your computer and use it in GitHub Desktop.
Save nkohari/650532 to your computer and use it in GitHub Desktop.
Given a regex, will remove all CSS classes that match from an element.
jQuery.fn.extend({
removeMatchingClasses: function(pattern) {
return this.each(function() {
var element = jQuery(this);
var classes = element.attr("class").split(/\s+/);
jQuery.each(classes, function(idx, class) {
if (class.match(pattern)) element.removeClass(class);
});
return this;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment