first remove active class from classlist and append to current element using javascript
snippet in javascript

first remove active class from classlist and append to current element using javascript

user1499

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