remove class by pattern

The removeClass function takes a function argument since jQuery 1.4.

by Yury

HTML

<div id="hello" class="color-red color-brown foo bar">Hello!</div>
<div id="good_bye" class="moved-to1 moved-to2 foo bar">Good bye!</div>

CSS

div.foo{
    border: 1px solid teal;
    padding: 3em;
    margin: 1em;
    transition: all 1s;
}
div.color-brown{color: brown;}
div.color-red{color: red;}
div[class*="color-"] {padding-left: 40%;}
div.moved-to1{margin-left: 20%;}
div.moved-to2{margin-left: 40%;}
div[class*="moved-to"]{padding: 8em;}

JavaScript

setTimeout(function(){
    $("#hello").removeClass (function (index, css) {
        return (css.match (/\bcolor-\S+/g) || []).join(' ');
    });
}, 3000);
    
console.log($("#hello"));


setTimeout(function(){
    $("#good_bye").removeClass (function (index, css) {
        return (css.match (/\bmoved-to\S+/g) || []).join(' ');
    });
}, 6000);