i want to apply class to tr depending on td cell value in a table .
my html
<table class="k-focusable">
<tr>
<th>Name</th>
<th>Favorite color</th>
<th> status</th>
</tr>
<td>James</td>
<td>red</td>
<td>false</td>
</tr>
<tr>
<td>John</td>
<td>blue</td>
<td>true</td>
</tr>
</table>
var cellIndexMapping = { 2: true };
$("table.k-focusable tbody tr").each(function (rowIndex) {
$(this).find("td").each(function (cellIndex) {
if (x[cellIndex]) {
var c = $(this).text();
if (($.trim(c) == "false") || ($.trim(c) == "null")) {
$("table.k-focusable tbody tr").find("td").addClass("hover");
}
}
});
});
.hover
{
font-weight:bold
}
when i am doing this, every row is having this class hover.But i want that class to be add only if the td value is false or null.
Try this
Check Fiddle
You don’t need the second
$.eachto iterate over the td’s in the first place.You can then reference the
tdyou want to change with this