# Change Background color using hex color in wix dataset

**URL:** <https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [December 23, 2021, 5:58am UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265 "2021-12-23T05:58:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![david12252006](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/david12252006/32/27969_2.png) [@david12252006](https://forum.wixstudio.com/u/david12252006)\
**Post date:** [December 23, 2021, 5:58am UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/1 "2021-12-23T05:58:49Z")

</div>

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

 ![](https://us1.discourse-cdn.com/wix/original/3X/0/6/061b5429b56b0e023e8a30e59bec40f3643e7609.png)

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

```

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [December 23, 2021, 8:51am UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/2 "2021-12-23T08:51:36Z")

</div>

Setting the [style.backgroundColor](https://www.wix.com/velo/reference/$w/box/style) property should work. Where do you have this code? Perhaps you need to wrap this code in a [dataset onReady()](https://www.wix.com/velo/reference/wix-dataset/dataset/onready) to ensure that the dataset is ready before your code runs.

---

<div class="post-metadata">

**Author:** ![david12252006](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/david12252006/32/27969_2.png) [@david12252006](https://forum.wixstudio.com/u/david12252006)\
**Post date:** [December 23, 2021, 5:57pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/3 "2021-12-23T17:57:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [December 23, 2021, 6:07pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/4 "2021-12-23T18:07:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david12252006](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/david12252006/32/27969_2.png) [@david12252006](https://forum.wixstudio.com/u/david12252006)\
**Post date:** [December 23, 2021, 6:08pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/5 "2021-12-23T18:08:30Z")

</div>

@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 ;  
});

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [December 23, 2021, 6:09pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/6 "2021-12-23T18:09:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jim75924](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jim75924/32/17468_2.png) [@jim75924](https://forum.wixstudio.com/u/jim75924)\
**Post date:** [December 23, 2021, 6:13pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/7 "2021-12-23T18:13:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [December 23, 2021, 6:19pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/8 "2021-12-23T18:19:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jim75924](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jim75924/32/17468_2.png) [@jim75924](https://forum.wixstudio.com/u/jim75924)\
**Post date:** [December 23, 2021, 6:22pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/9 "2021-12-23T18:22:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [December 23, 2021, 6:46pm UTC](https://forum.wixstudio.com/t/change-background-color-using-hex-color-in-wix-dataset/265/10 "2021-12-23T18:46:04Z")

</div>

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

```javascript
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.
