$.fn.removeClassPrefix = function(prefix){ var c, regex = new RegExp("(^|\\s)" + prefix + "\\S+", 'g'); return this.each(function(){ c = this.getAttribute('class'); this.setAttribute('class', c.replace(regex, '')); }); };