Here's my fiddle https://jsfiddle.net/tuc1faug/1/ Here I have assigned the colors with the specific values using jquery. Colors will be shuffled each time.Now i want these values to be hidden in the cells and I want all those values to be stored into an array in that shuffled order Html:
<table border="5px" width="500px" height="50px" align="center">
<tr id="colors">
<td height="50px" orderId="1" bgcolor="red"></td>
<td height="50px" orderId="6" bgcolor="brown"></td>
<td height="50px" orderId="5" bgcolor="pink" ></td>
<td height="50px" orderId="0" bgcolor="blue" ></td>
<td height="50px" orderId="7" bgcolor="black"></td>
<td height="50px" orderId="2" bgcolor="green"></td>
<td height="50px" orderId="4" bgcolor="orange" ></td>
<td height="50px" orderId="3" bgcolor="yellow"></td>
</tr>
</table>
jQuery:
var arr=[];
var colorCells =document.getElementById('colors').getElementsByTagName('td');
var colors = ["blue","red","green","yellow","orange","pink","brown","black"];
for(var i = 0; i < colorCells.length; i++) {
$(colorCells[i]).attr("bgColor", colors.splice(Math.random() * (colors.length),1)) ;
arr.push(colorCells[i].style.backgroundColor);
}
var colorValues = {"red": 2, "blue":3, "green": 4, "yellow":"1", "orange":5, "black":1, "brown":6, "pink":5};
$("table td").each(function() {
$(this).html(colorValues[$(this).attr("bgColor")]);
});