Here is my code, setWord is 1985:
$("td:contains(" + setWord + ")").css("textDecoration", "underline");
I thought this would do the trick:
$("td").not(":contains(" + setWord + ")").parent().css("backgroundColor", "red");
But apparently not. I’m just trying to select that TD’s parent TR
<tr>
<td>John</td>
<td>03/09/1985</td>
<td>Red</td>
<td>Australia</td>
<td>$ Dollars</td>
</tr>
<tr>
<td>Dave</td>
<td>01/01/1987</td>
<td>Blue</td>
<td>London</td>
<td>£ Pounds</td>
</tr>
If the idea is to change the background of all rows that do not contain the
setWord“1985” then try this:Demo: http://jsfiddle.net/kwH6L/
If the idea is to change the background of rows that do contain the
setWordthen try this:Demo: http://jsfiddle.net/kwH6L/1/
The problem with the code you showed:
…is that you start by selecting all TD elements, then remove the ones that contain the
setWord, but that still selects at least some TD elements in every row. So then when you get the.parent()of the selected TDs you get every TR element…