I have an 'order' table where the first column is the ID of orders. I want to set the background-color dependent on the last number of the ID column.
For example, if the Id is 23433 I want to be the color to be #adcbe3. I've tried the code below, but it's not working.
$(function() {
$("tr").each(function() {
var firstCol = $("tr").find("td:first");
var reg1 = new RegExp("^[0-9]*[0369]$", 'g');
var reg2 = new RegExp("^[0-9]*[147]$", 'g');
var reg3 = new RegExp("^[0-9]*[258]$", 'g');
if (String(firstCol).match(/^[0-9]*[0369]$/)) {
$(this).addClass('row1'); //the selected class colors the row green//
} else if (String(firstCol).match(/^[0-9]*[147]$/)) {
$(this).addClass('row2');
} else if (String(firstCol).match(/^[0-9]*[258]$/)) {
$(this).addClass('row3');
}
});
});
.row1 {
background: #adcbe3;
}
.row2 {
background: #e7eff6;
}
.row3 {
background: #d0e1f9;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>