Event listener

Hello everyone,

I’m building my portfolio website, so I decided to make a small menu using JS. What I wanted to do is when the user click on the menu button the menu will pop up and the color of the text and the background will change, and I did that successfully using addEventListener. However, when I click away from the button, the changes will not go back to default. How can I reverse that to make it go back to default when the user click away from the button.

Thank you :blush:

One technique to look for is class switching. We can have two listeners, one on each class. Each handler toggles the class name of the target element so that the event listeners trade places.

1 Like