Wix code change background color

Hi,

I’m trying to change background color of a button (I’m trying to change it to green for a second, to indicate that action was successful, and then return the color to it’s original).
I can easily the background color with line such as:

  $w(id).style.color = "rgba(0,200,100,1)";

but I’m having problem with reading the color, since I’m getting something like: “color_23”, and I can’t set the color to:

  $w(id).style.color = "color_23";

and I don’t know how to get the RBG color from “color_23”, or access colors in some kind of current site pallet.

Here’s the function that’s supposed to blink a button for a second to different color and then return color to what it was before.

function blinkBgColor(id, color, timeMs) {
    let prevBgColor = $w(id).style.backgroundColor;
    console.log(prevBgColor); // prints "color_23" to logs
    $w(id).style.backgroundColor = color;
    setTimeout(function() {
        $w(id).style.backgroundColor = prevBgColor; // throws following error:
            //Wix code SDK error: The "backgroundColor" property of "someButton" was set to an invalid "rgbaColor" value. The value is expected in one of the following formats: "red", "#FF0000", "#FF000000", "rgb(225, 0, 0)" or "rgba(225, 0, 0, 0)"". 
        }, timeMs);
}

//It's supposed to be used like this:
    blinkBgColor("#someButton", "rgba(0,200,100,1)", 1000);

Any help of hint would be appreciated.

Hello

I suggest you set it to the hex value of your button’s color:

  $w(id).style.color = "#7FCCF7"; 

Best
Massa

I’m aware of that option, and it’s not helpful. I’d have to write specific function for each button, and what’s worse - if I change the color theme, I’d have 30 places in code where I’d have to update color. That would obviously be a very stupid approach.

@littlebeargamesdoo Then you do a

var buttonColour = "yourHexCode";

and use this in the other places:

$w(id).style.color = buttonColour;