2

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"]' );
2
  • You want to find if the link has the departments=1 and contains with /browse/buy/? If not, can you please clearly explain the requirements that you have? Commented Aug 25, 2013 at 15:08
  • If we are to assume the element at the top, why would you make the selector more specific so as to exclude the given element? I can't tell what your actual issue is. How does using the absolute path of the current page factor in? Commented Aug 25, 2013 at 15:11

1 Answer 1

7

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"]');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.