How can I toggle between 2 classes on click on the same element on JS

Need your help on something,

Trying to toggle between classes when I click on an element on an HTML page but unfortunately once toggled I cannot change it back.

Even tried returning the querySelector but no luck.

Here is the code I wrote;

let fetchNumbers = document.querySelectorAll(`.cardnumber`);

    for (let index = 0; index < fetchNumbers.length; index++) {
    
    if (fetchNumbers[index].classList.contains('unselected') === true) {
        fetchNumbers[index].addEventListener(`click`, function () {
            fetchNumbers[index].classList.add(`selected`);
            fetchNumbers[index].classList.remove(`unselected`);
            fetchNumbers = document.querySelectorAll(`.cardnumber`);
            return fetchNumbers;
        }); 
    } else {
        fetchNumbers[index].addEventListener(`click`, function () {
            fetchNumbers[index].classList.add(`unselected`);
            fetchNumbers[index].classList.remove(`selected`);
            fetchNumbers = document.querySelectorAll(`.cardnumber`)
            return fetchNumbers;
        }); 
    }
}

Thank you in advance