function myFunction(e) { if (document.querySelector('#navList a.active') !== null) { document.querySelector('#navList a.active').classList.remove('active'); } e.target.className = "active"; }