Answer the question
In order to leave comments, you need to log in
How to remove a class through a loop?
Hello, please tell me how to remove the class from all child elements when clicking on one.
<ul class="list">
<li class="item">item1</li>
<li class="item">item2</li>
<li class="item">item3</li>
</ul>
.red{
color:red;
}
const list = document.querySelector('.list')
list.addEventListener('click', (event) =>{
const target = event.target
target.classList.add('red')
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question