html:

<div class="foo1 foo2 foo3 bar1 foo4">Sample Text</div>

javascript:

var regEx = /^foo/;
var elm = $("div");

var classes = elm.attr('class').split(/s+/); //it will return  foo1, foo2, foo3, foo4

for (var i = 0; i < classes.length; i++) {
  var className = classes[i];
	
  if (className.match(regEx)) {
	elm.removeClass(className);
  }
}

or a simple regExp

var elm = $("div");
var regEx = /^foo[0-9]*/;
elm[0].className = elm[0].className.replace(regEx, '');
Advertisements