Here is my code:
var randomColor = ["red", "blue", "green", "#9CBA7F", "yellow", "#BF5FFF"];
function setRandomColor() {
return randomColor[Math.floor(Math.random() * randomColor.length)];
}
$('.mastermind_master_cpu').each(function() {
$(this).find('td').each(function() {
$(this).css("background-color", setRandomColor);
})
})
As you can see, the mastermind_master_cpu table will randomly fill with different background color. The problem is I have ten different tables and am repeating this every time. Does anyone know how I can go about making this just one function / variable and calling it when needed?
Thanks!
.css(). The point is that it iterates a collection, but you're passing it to a collection with a single element. Why not$(this).find("td").css("background-color", setRandomColor)?