I want to maintain color on clicked button - reopen

I would like to change and maintain the background color for each of the buttons when clicked, so that the user can easily see what filter he activated browsing the books on that page.

I already found the code from @J.D. in a closed thread and applied it:

$w.onReady(function () {
 let buttonsToChange = [$w("#alle"), $w("#beziehungen"), $w("#business"), $w("#bewusstsein"), $w("#selbsterkenntnis"), $w("#psychologie"), $w("#geschichten")];//put the relevant buttons here
    buttonsToChange.forEach(button => {
        setButtonColor(button, 1);
        button.onClick((event) => {
            buttonsToChange.forEach(b => {
                setButtonColor(b, 0);
            });
        setButtonColor(button, 1);
    })Wues

The problem:

  1. it is only working for the business button - how to make the others work too?

  2. the business button is already white when loading the page. How can I set the #alle button to appear white up front

Would be so happy if someone or J.D. could help me with this, since I am really stuck on this one

Thank you so much!

1 Like

Hi Philipp,
You need to do some changes in the code to make it to work when each button is clicked. And reset the buttons that are not clicked. PM if you don’t know how to do it. I can write code for you.

Thank you very much - somehow I can´t send you a PM. Do you know why?