I am working on a requirement where I have to highlight a row or column on a checkbox selected as in the image below.
Now, how do I change the code so that the overlay cell is assigned a new color instead of green or yellow? As in this image below, Jackson should be highlighted in a different color - blue.

the code:
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
$(document).ready(function () {
$("input[type='checkbox']").change(function (e) {
if ($(this).is(":checked")) {
$(this).closest('tr').addClass("highlight");
} else {
$(this).closest('tr').removeClass("highlight");
}
});
$('th').click(function () {
var $currentTable = $(this).closest('table');
var index = $(this).index();
$currentTable.find('tr').each(function () {
$(this).find('td').eq(index).toggleClass('selectedcc');
});
});
});
</script>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
.highlight td {background: yellow;}
.selected {
background-color: yellow;
}
.selectedcc {
background-color: greenyellow;
}
</style>
</head>
<body>
<table style="width:60%" id="dataTable">
<tr>
<th><input type="checkbox" name="vehicle" value="Bike">All</th>
<th><input type="checkbox" name="vehicle" value="Bike">Firstname</th>
<th><input type="checkbox" name="vehicle" value="Bike">Lastname</th>
<th><input type="checkbox" name="vehicle" value="Bike">Points</th>
</tr>
<tr>
<td><input type="checkbox" name="vehicle" value="Bike"></td>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td><input type="checkbox" name="vehicle" value="Bike"></td>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td><input type="checkbox" name="vehicle" value="Bike"></td>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
source
share