Reputation: 1077
I want it to ignore the <td>
that has a parent of class .ignore
. Here is what I have now, but it styles every <td>
.
<script>
$('td:nth-child(2)').css('background-color', 'rgb(255, 248, 231)');
</script>
<table>
<tr>
<td> </td>
<td>select</td>
<td> </td>
</tr>
<tr class="ignore">
<td> </td>
<td>don't select</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>select</td>
<td> </td>
</tr>
</table>
Upvotes: 0
Views: 149
Reputation: 9825
You can do something like this:
$('td:nth-child(2)').each(function(){
if ($(this).closest('tr').hasClass('ignore') === false){
$(this).css('background-color', 'rgb(255, 248, 231)');
}
});
Upvotes: 0
Reputation: 5699
$('td:nth-child(2)').not('tr.ignore td').css('background-color', 'rgb(255, 248, 231)');
Upvotes: 0
Reputation: 47667
$('tr:not(.ignore) td').css('background-color', 'rgb(255, 248, 231)');
Upvotes: 3