How to replace class of the elements having a specific class?

Current code is <i class="arrow-right"></i>

I want to replace class in all <i> elements having "arrow-right" with "new-arrows"

I tried it using JS.

function changeclass(newclass, elm) {
    elm.attr('class', function (i, oldClasses) {
        return newclass: oldClasses.replace(/\b(bg-[a-z]+)\b/i, return newclass;
    });
}

$('i').each(function () {
    changeclass('new-arrows', $(this));
});

1 thought on “How to replace class of the elements having a specific class?”

Leave a Comment