This code snippet works to remove an existing class, before adding a new one, when I specify it directly (ie, \'ratingBlock\', \'ratingBlock1\', \'ratingBlock2\', etc.). But
removeClass takes either a function or a class name. You are trying to provide a css selector. It looks like all you need is:
ratingBlock.removeClass('ratingBlock').addClass('ratingBlock' + rating)
Furthermore you could remove a wildcard like this:
ratingBlock.removeClass (function (index, css) {
return (css.match (/ratingBlock/g) || []).join(' ');
});
Reference: JQuery removeClass wildcard