# Randomizing elements in wix

**URL:** <https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 26, 2021, 5:22pm UTC](https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951 "2021-04-26T17:22:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rawn](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rawn](https://forum.wixstudio.com/u/rawn)\
**Post date:** [April 26, 2021, 5:22pm UTC](https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951/1 "2021-04-26T17:22:54Z")

</div>

Hello!  
Thank you to anyone who takes time to read/ help. I’m looking to randomize certain elements upon loading every new page of my website. I have pairs of color coordinated logos+background. ex. red background+red logo, blue background+blue logo, etc. The logo is in the header, and the background would apply to every page. does anyone have good direction on how to do this? I’m not sure how to set the image path from Wix’s UI.  
Thanks again!

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [April 26, 2021, 7:39pm UTC](https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951/2 "2021-04-26T19:39:00Z")

</div>

Hi,  
Please clarify your question and explain in details, because I don’t understand what exactly you’re trying to do.

---

<div class="post-metadata">

**Author:** ![rawn](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rawn](https://forum.wixstudio.com/u/rawn)\
**Post date:** [April 27, 2021, 12:47am UTC](https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951/3 "2021-04-27T00:47:01Z")

</div>

I would like the background image and the image in my header to randomize upon loading the webpage. For example, the background and the company logo are both red, i refresh the page and they are both blue, i refresh the page again and this time its green, but i am trying to make it random.

---

<div class="post-metadata">

**Author:** ![rawn](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rawn](https://forum.wixstudio.com/u/rawn)\
**Post date:** [April 27, 2021, 12:48am UTC](https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951/4 "2021-04-27T00:48:36Z")

</div>

i already have all images made in different colors, and uploaded to my image collection on wix.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 27, 2021, 6:16am UTC](https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951/5 "2021-04-27T06:16:57Z")

</div>

Take a look at this example here…  
[https://russian-dima.wixsite.com/meinewebsite/random-numbers-strings](https://russian-dima.wixsite.com/meinewebsite/random-numbers-strings)

And learn how to generate some random values.

---

<div class="post-metadata">

**Author:** ![volkaertskristof](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/volkaertskristof/32/18158_2.png) [@volkaertskristof](https://forum.wixstudio.com/u/volkaertskristof)\
**Post date:** [April 27, 2021, 6:43am UTC](https://forum.wixstudio.com/t/randomizing-elements-in-wix/1951/6 "2021-04-27T06:43:00Z")

</div>

Hi Rawn,

The way i would do it.  
Make an array with the color’s / backgrounds you want to be able to shown.

```javascript
const array = 
[{
image:imagesource1,
color:color1
},{
image:imagesource2,
color2
}]

```

Then as you load a page, generate a random number like @russian-dima said.

Be sure the random number isn’t higher then the array length

Then use that random number to select the a background/color and use it to change the page background.

```javascript
$w("#page").background.src

```

Kind regards,  
Kristof
