Reputation: 64793
Assume I have this url:
<a href="/browse/buy/?departments=1">Phones</a>
And I want to match it via jQUery, the problem is, link is a subset of the queried test as this as I want to use the absolute path of the current page to find the fitting link (as my page may contain more additional get parameters like /browse/buy/?departments=1&order_by=title
:
Yet None of them worked:
$( 'a[href*="/browse/buy/?departments=1&order_by=title"]' );
$( 'a[href^="/browse/buy/?departments=1&order_by=title"]' );
$( 'a[href$="/browse/buy/?departments=1&order_by=title"]' );
Upvotes: 2
Views: 3498
Reputation: 219920
If you want to find if the link has the departments=1
and contains with /browse/buy/
, use this:
$('a[href*="/browse/buy/"][href*="departments=1"]');
Upvotes: 7