I have an html table and I want to color the rows based on the value in the first column of that row. If the value is CONFIRMED I want to color the row green, and if it is UNCONFIRMED I want to color the row red.
The JS I am using to do this is:
$(function(){
$(tr).each(function(){
var col_val = $(this).find(td:eq(1)).text();
if (col_val == CONFIRMED){
$(this).addClass('selected'); //the selected class colors the row green//
} else {
$(this).addClass('bad');
}
});
});
The CSS looks like this:
.selected {
background-color: green;
color: #FFF;
}
.bad {
background-color: red;
color: #FFF;
}
The html table is generated from a pandas dataframe in my Django view and passed in like this:
<div class=table-responsive style=margin-left: 15%; margin-right: 15%; overflow:auto;>
{{ datatable | safe }}
</div>
The problem is that it's coloring all of my rows red. Can anyone tell me what I'm doing wrong?