最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery select the link contains a url - Stack Overflow

programmeradmin1浏览0评论

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"]' );

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"]' );
Share Improve this question asked Aug 25, 2013 at 15:03 HellnarHellnar 65k82 gold badges208 silver badges282 bronze badges 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? – David Thomas 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? – user2437417 Commented Aug 25, 2013 at 15:11
Add a ment  | 

1 Answer 1

Reset to default 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"]');
发布评论

评论列表(0)

  1. 暂无评论