Skip to content
Advertisement

Change the background-color on a button after clicking

Hello i write on a rating button and i wanted to change the background color from the button after i clicked it but my code does nothing.

JavaScript

Advertisement

Answer

const btn = document.querySelector('.btn'); is only targeting the first button.

You need to use querySelectorAll to select all buttons and add event listeners to each of them.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement