Trying to get the color of my button to change from Blue to red

But the code doesn’t seemed to be working.

Are you trying to make it so the button is always red? Or do you want it to turn red when it is pressed?

trying to get it to changed to red when pressed

Did a little experimenting with your code, the problem is this:'red';

lips was declared as document.getElementsByClassName('btn'). getElementsByClassName() returns ALL elements that have that class name as an array. So, even if you only have one btn, lips is an array with length of 1.

So, you can either access the first (and only) element in the array and change its style, or, when you declare lips, you can use document.getElementById(), which will return a single value.

I made this change to your code and it is working for me. Please let me know if you are still having trouble or if my explanation doesn’t make sense.

I updated my code to include an id element for my input button html element and I still have the same issue.

what did you do?

it’s getElementById, singular, as you should have only one element with that id - you have used “elements” there

1 Like

Thanks . That worked.