this how you can do it.
const linkList = document.querySelectorAll('.sidemenu');
const link = document.querySelector('.sidemenu');
link.addEventListener('click', e => {
let $this = e.target;
linkList.forEach(ele => {
ele.classList.remove('active');
});
$this.classList.add('active');
});
javascript interpreter in browser read script from top to bottom so first we get the list of items have calss .sidemenu
by declaring consistent variable linkList
then we get the one element node by declaring another consistent variable link
after we make click event inside we declare variable $this
to refer to the event target (the element i have clicked) then we make loop on all links that have .sidemenu
class to remove class active
then out side the loop and in event block we add active
class to the target (the element i have just clicked)