EventListener Not Working

Hey,

What am I getting wrong here? The event listener isn’t running for some reason.

Thanks

const toggle = document.querySelector('.toggle');
const item = document.querySelector('.item');

toggle.addEventListener('onClick', () => {
    if (item.classList.contains('active')) {
      item.classList.remove('active');
    } else {
      item.classList.add('active');
    }
});

It’s not “onClick”. It’s just “click”.

1 Like

The event is just click, not onClick.

Edit: Too late. Anyway, I’m guessing you are thinking of React.

1 Like

Ya, I’ve got React on the brain. Thanks!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.