-1

I wrote the following to manually make changes to a button when clicked

const links = document.getElementsByTagName('a');


links.addEventListener('click', () => {
  links.classList.add('clickedLink');
})

..but the threw an error

TypeError: links.addEventListener is not a function at /script.js:4:7'

..what seems to be the problem?

1 Answers1

0

It says getElements,hence more elements,so you should run a loop for adding the event listeners on each element

for(let link of links){
link.addEventListener...
}
vonsii
  • 31
  • 3