Reputation: 13067
The document I am parsing has the following two styles of td
tags (among other instances of td
tags):
<td align="right" nowrap bgcolor="#A1C87A">...</td>
<td align="right" nowrap>...</td>
How do I write a selector which only selects the second type, and exclude all the other td
tags?
document.css('td:not([bgcolor="#A1C87A"])')
excludes the first type, includes the second type plus all other td
tags as well.
document.css('td[align="right"][nowrap]')
excludes all other td
tags, but includes both types above.
Upvotes: 9
Views: 5825
Reputation: 79743
You can simply combine the :not
selector with the other attribute selectors:
document.css('td:not([bgcolor="#A1C87A"])[align="right"][nowrap]')
You could even put the :not
after the others (it doesn’t need to be right next to the element name):
document.css('td[align="right"][nowrap]:not([bgcolor="#A1C87A"])')
These will both select all td
elements that have bgcolor="#A1C87A"
and nowrap
but don’t have align="right"
, which is what you’re after.
Upvotes: 14
Reputation: 13176
td:not([align="right"][nowrap][bgcolor])
should be enough for what you want
Upvotes: 0