Im working with this part of code
<div class="single-select">
<div class="single-title">
<p class="title">User answear</p> <img src="../resources/chevron-down.svg" alt="">
</div>
<ul id="single-select-dropdown">
<li class="option" id="option1">answear 1 <img src="../resources/checkmark.svg" alt=""></li>
<li class="option" id="option2">answear 2 <img src="../resources/checkmark.svg" alt=""></li>
<li class="option" id="option3">answear 3 <img src="../resources/checkmark.svg" alt=""></li>
</ul>
</div>
const dropdownOptions = document.querySelectorAll('.single-select .option');
dropdownOptions.forEach(option => option.addEventListener('click', handleOptionSelected));
function handleOptionSelected(e) {
const newValue = e.target.textContent + ' ';
const titleElem = document.querySelector('.single-title .title');
titleElem.textContent = newValue;
e.target.classList.add('active')
}
Everytime when i choose option JS should add to class list class 'active'. The point is that only single option can have this class on it. Can someone help me how to remove it everytime when i choose other option?