My js code is not working can anyone find error

There are many <li/> with class name list and one having active too and I wanna give active class name to <li/> on clicking

const list = document.querySelectorAll('.list');

function activeLink(){
    list.forEach((element) =>
      element.classList.remove('active')
    );
    this.classList.add('active')
}

list.forEach((element) => 
  element.addEventListener('click',activeLink)
)