Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Event Listener not working

Here I have a button:

<button class = corner-add>Corner Add</button>

I want that button to turn a lighter shade of green when you mouseover it, so I used te following code:

buttons[4].addEventListener('mouseover', () => {
        buttons[4].style.backgroundColor = '#21897E';
      });

      buttons[4].addEventListener('mouseout', () => {
        buttons[4].style.backgroundColor = '#2E9763';
      });

But it does not work, why is this?

This is the fifth button in the program btw

1 Answer

try putting your class name inside parentheses, I think that's the problem :)

Sorry to be so intuitive, but why would putting parentheses around the class name fix it?

Honestly, the js part looked fine to me I haven’t seen the challenge and the first mistake I saw was the missing paranthese around the class. I assume that if so, when trying to add the css rule it wont work as it should. I don’t see the entire code and this was just a guess.

I was never taught that the class name goes in parentheses

Oops sorry abou that I was aiming for quotes, but I write parentheses :) Thank you for the corection Jackson Monk

That's okay