1

EDIT: I made a typo in the question, my apologies.

<td><span class="price"></span></td> //selected
<td></td>          //I want this guy to be selected as well!
<td><span class="price clearance"></span></td>

I basically want: Select all td that don't have span.clearance. This includes td that don't have span as well.

I tried $('td span:not(".clearance")'); it doesn't select <td></td>. Any clues?

4

4 回答 4

4

You don't need quotes on your inner not() selector.

Try this:

$('td span:not(.clearance)');

Edit:

Since you mentioned you also want empty tds returned, try this jQuery selector:

$('td span:not(.clearance), td:not(:has(span))');
于 2013-03-24T05:47:07.323 回答
1

It works fine for me.

Please refer below code.

console.log($('td span:not(.clearance)'));

http://jsfiddle.net/5Wbye/1/

Thanks,

Siva

于 2013-03-24T06:11:58.517 回答
0
$('td > span:not(.clearance)');   try this one.
于 2013-03-24T05:50:46.097 回答
0

Try the following:

<script type="text/javascript">
    $(document).ready(function() {
        $('td span:not(".clearance")').css('border','5px solid red');
    });
</script>
<table>
   <tr>
      <td style="border:5px solid green;"><span class="price">1</span></td>
      <td>2</td>
      <td><span class="price clearance">3</span></td>
   </tr>
</table>

I don't think anything is wrong with your original post besides the fact that your table is missing <table> and <tr> tags

于 2013-03-24T06:04:12.747 回答