@kimchiver
Posted
document.querySelectorAll
returns an array, so you can check each element of the array ( if document.querySelectorAll(".rating-value")[i].classList.contains("active")
). otherwise you can store a reference to the previous selected item in a global variable:
let previousSelected = null
ratingsContainer.addEventListener('click', (e) => {
...
if ( previousSelected ) previousSelected.classList.remove('active');
previousSelected = e.target;
e.target.classList.add('active')
...
}
Marked as helpful
@unachoza
Posted
@kimchiver
thank you; I appreciate your review! Reminding me that document.querySelectorAll
returns an array, I realized I can use forEach
to get the removal task done :)