Hellnar
Hellnar

Reputation: 64793

jQuery select the link contains a url

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

Answers (1)

Joseph Silber
Joseph Silber

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

Related Questions