ehabd
ehabd

Reputation: 1077

Select TD elements, except the ones in these parent TR

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

Answers (3)

dSquared
dSquared

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)');
    }
});

Demo Here

Upvotes: 0

Lowkase
Lowkase

Reputation: 5699

$('td:nth-child(2)').not('tr.ignore td').css('background-color', 'rgb(255, 248, 231)');​

http://jsfiddle.net/3TrxJ/

Upvotes: 0

Zoltan Toth
Zoltan Toth

Reputation: 47667

$('tr:not(.ignore) td').css('background-color', 'rgb(255, 248, 231)');

DEMO

Upvotes: 3

Related Questions