JSFiddle - React, Tailwind, and code Playground
HTML
<table id="sortable">
<tbody>
<tr>
<td class="content">A</td>
</tr>
<tr>
<td class="content">B</td>
</tr>
<tr>
<td class="content">A</td>
</tr>
<tr>
<td class="content">C</td>
</tr>
<tr>
<td class="content">C</td>
</tr>
</tbody>
</table>
JavaScript
function random_rgba() {
var o = Math.round, r = Math.random, s = 255;
return 'rgba(' + o(r()*s) + ',' + o(r()*s) + ',' + o(r()*s) + ',' + r().toFixed(1) + ')';
}
$(function() {
var tableRows = $("#sortable tbody tr"); //find all the rows
var rowValues = {}; //to keep track of which values appear more than once
var color = "";
tableRows.each(function() {
var rowValue = $(this).find(".content").html();
if (rowValues[rowValue]){
color = rowValues[rowValue];
}else{
color = random_rgba();
rowValues[rowValue] = color;
}
$(this).css('backgroundColor', color);
});
});