var el = document.querySelector('.nav-link.active'); el && el != this && el.classList.remove('active'); this.classList.toggle('active');