Create a class, say random_color
, to apply to each table in addition to your current class, like this:
<table class="mastermind_master_cpu random_color">...</table>
Then you can just use this once:
$('.random_color').each(function() {
$(this).find('td').each(function() {
$(this).css("background-color", setRandomColor);
})
})
But as cookie monster points out, this can be done much more succinctly:
$('.random_color td').css("background-color", setRandomColor);