R
R
Rem362021-07-01 19:08:19
JavaScript
Rem36, 2021-07-01 19:08:19

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 question

Ask a Question

731 491 924 answers to any question