如何根据td为tr添加css属性

Fin*_*ngs 1 javascript jquery

我想根据表中的td单元格值将类应用于tr.

我的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
}
Run Code Online (Sandbox Code Playgroud)

当我这样做时,每一行都有这个类悬停.但我希望只有在td值为false或null时才添加该类.

Adi*_*dil 5

试试这个

$("table.k-focusable tbody tr td:contains('false')")
Run Code Online (Sandbox Code Playgroud)