Agorreca
Agorreca

Reputation: 686

jQuery: Selector to use 'logical AND' over the same attribute

Having something like this:

<div>
    <a href="http://a.site.org/a_link.html"></a>
    <a href="http://a.site.org/file_name.rdf"></a>
    <a href="http://a.site.org/file_features_name.rdf"></a>
    <a href="http://a.site.org/file_features2_name.rdf"></a>
</div>

How can I get only those links where the href attribute ends with rdf AND doesn't contain features?

I know I can use:

$('a[href$=".rdf"]')

to get all the .rdf files. Any idea?

Upvotes: 2

Views: 128

Answers (2)

gdoron
gdoron

Reputation: 150253

I would use this:

$('a[href$=".rdf"]').not('[href*=features]')

Also can be written as one selector with:

$('a[href$=".rdf"]:not([href*=features])')

But I think it is less readable.

As always code for humans not for machines.

Upvotes: 4

Naftali
Naftali

Reputation: 146310

Add on the :not(..) selector:

$('a[href$=".rdf"]:not([href*="features"])')

Upvotes: 3

Related Questions