Javascript change style of all buttons with a certain class doesn’t work

I have multiple buttons, some with the same classname. When one button is pushed, I want all the other buttons with the same classname to change with it. I made a loop to calculate the length of the queryselector and make sure it applies is to all buttons, but it doesn’t work.

 let buttons = document.querySelectorAll('.v' + tgt.value);
// when console.log(buttons) the right buttons are shown

            for(let i = 0; i < buttons.length; i++) {
                let btn = buttons[i];
                if (quizUrl.indexOf(tgt.value) === -1) {
                    quizUrl.push(tgt.value);
                    btn.style.backgroundColor = "white";
                    btn.style.color = "black";
                    console.log(btn)
                    // Check if a button is clicked again. If clicked again changes color back and deletes value in the url array
                } else {
                    quizUrl.splice(quizUrl.indexOf(tgt.value), 1);
                    btn.style.backgroundColor = "transparent";
                    btn.style.color = "white";
                }
            }

But with this only one button changes and it won’t even change back.