Need some help with Javascript.
Description: there are 3 different color combinations (pallets). Every combination has 3 colors.
Goal: randomly choose color combination on page load and change elements like: background-color, font-color, underline-color.
Problem: can't figure out how to make it for color combination, but not a 1 color like in code example below.
Example:
- Pallet-1: red, blue, green
- Pallet-2: yellow, cyan, orange
Pallet-3: cyan, orange, blue
- Script randomly choosing Pallet-2.
- Change background-color to yellow, font-color to cyan, border-color to orange.
Sorry if it's too simple, but I spent a day and found a solution for random color pick of 1 color only from the list, but can't make it work with color combinations.
Thanks in advance.
JS:
$(document).ready(function(){
var colors = ['red','blue','green','yellow','cyan','orange'];
var new_color = colors[Math.floor(Math.random()*colors.length)];
$('#color-div').css('background-color',new_color);
});
CSS:
#color-div{
border:1px solid gray;
width:50px;
height:50px;
}
HTML:
<div id="container">
<div id="color-div">
</div>
</div>