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

Assume I have this url:<a href=​"​browse​buy​?departments=1">​Phones​<a>​And

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745185361a4615611.html

相关推荐

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

    Assume I have this url:<a href=​"​browse​buy​?departments=1">​Phones​<a>​And

    12小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信