Change Background color using hex color in wix dataset

Hi. i dont know if this will make much sense but i would like to change the color of a box based on an item from my dataset.

My dataset has the background color already set with a hex code however when i tell the code to pair with the “#” it wont change the color. Heres my code

var color = item.shopImageBackgroundColor;
var colorReady = "#" + color;
$w("#box57").style.backgroundColor = colorReady;

Setting the style.backgroundColor property should work. Where do you have this code? Perhaps you need to wrap this code in a dataset onReady() to ensure that the dataset is ready before your code runs.

It still didnt work sadly. Is there anything else that might work

Without sharing your code there’s no way any of us can help.

@yisrael-wix Heres my code:

$w ( “#dynamicDataset” ). onReady ( () => {
let item = $w ( “#dynamicDataset” ). getCurrentItem ();
var color = item . shopImageBackgroundColor
var colorRea2dy = “#” + color ;

$w ( “#box57” ). style . backgroundColor = colorRea2dy ;
});

@david12252006 And where is this code? Where is it called? What function is it in?

I’ll admit to limited knowledge about hex color values, but are those values valid? I tested Yisrael’s suggested solution but removed the trailing ‘ff’ on each of the codes, and it worked.

Hmm - I actually tried a few of the values that he had in his chart and they worked. Could it be that the trailing ff is the opacity? Could it be that too many beers affected my opacity?

@yisrael-wix Ah, ok. Like I said, my knowledge level is limited. The examples I tried with the ‘ff’ came up black.

@jim75924 Hey Jim, you could be on to something. I tried this:

var colorReady = "#" + 'ff0000';

… and I got a red background. Make sense when you realize that the format is rrggbb (red, green, blue).

I’m giving you a Best Answer.