I am working with a table and need to format specific data fields based on their content. For instance, any field less than 95% should be highlighted in red.
Below is the jQuery code I am using:
$(function(){
$('#ConditionalTable td:nth-child(2n - 4)').each(function(){
var Sales = $(this).text();
if (Sales > '95%') {
$(this).css('backgroundColor', '#f76e6e');
} else {
$(this).css('backgroundColor', '#99faa0');
}
});
});
Currently, this script selects every second column and changes its color to green.
However, my goal is to exclude the first 3 columns (which contain titles) and start applying the formatting from the 4th column onwards.
This means that only the 4th column, 6th column, 8th column, and so on, should have the formatting applied.
Furthermore, regardless of the value in the table, all cells seem to be turning green. According to my code, if Sales are greater than 95%, they should be green, otherwise red. However, this functionality does not seem to be working as expected.