There are a great many ways to do this & so I am curious about which is considered the ‘best’ way.
An example using forEach:
const listItems = document.querySelectorAll('li');
function vanish() {
this.classList.add('vanish');
}
listItems.forEach(li =>
li.addEventListener('click', vanish));
An example using e.target:
const list = document.querySelector('ul');
list.addEventListener('click', (e) => {
e.target.classList.add('vanish');
})