bflemi3
bflemi3

Reputation: 6790

How to find hrefs that contain multiple strings

I'm looking to find any anchor tags that have an href that contain example.com and DONT CONTAIN vendor_id. Something like this...

$('a[href*="example.com" && href!*="vendor_id"]')

here's an example of the anchor i would find... <a href="http://www.example.com/?vendor_id=1>

Is this possible? Thanks for your help!

Edit: I don't think there is a selector for 'does not contain' but does this work? $('a[href*="example.com"]:not([href*="vendor_id")')

Upvotes: 1

Views: 479

Answers (3)

hunter
hunter

Reputation: 63562

You can use an attribute selector and wrap the second attribute selector in a :not()

$('a[href*="example.com"]:not([href*="vendor_id"])')

working example: http://jsfiddle.net/hunter/X9qna/

Upvotes: 3

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76910

You could do:

$('a[href*="example.com"]').filter('a[href*="vendor_id"]').remove();

fiddle here: http://jsfiddle.net/Smpm4/

Upvotes: 0

coreyward
coreyward

Reputation: 80128

You can stack attribute selectors like this to achieve what you need:

a[href*="example.com"][href!*="vendor_id"]

Upvotes: 1

Related Questions