Garmaine Staff asked 2 years ago

I would like to remove a class from one element when I clicked another?

could you help me please

<div class="tab">
    <button class="btn">Click Me</button>
</div>

<div class="tab">
    <button class="btn">Click Me</button>
</div>


    const dots = document.querySelectorAll('.btn');
    dots.forEach(dot => dot.addEventListener('click', handleClick));

    function handleClick(e) {
        this.classList.toggle('open');
        for (i = 0; i < dots.length; i++) {
            if (dots.classList.contains('open')) {
                dots.classList.remove('open');
            } else {
                dots.classList.add('open');
            }
        }

    }