Select which href ends with some string

2019-01-01 01:43发布

问题:

Is it possible using jQuery to select all <a> links which href ends with \"ABC\"?

For example, if I want to find this link <a href=\"http://server/page.aspx?id=ABC\">

回答1:

   $(\'a[href$=\"ABC\"]\')...

Selector documentation can be found at http://docs.jquery.com/Selectors

For attributes:

= is exactly equal
!= is not equal
^= is starts with
$= is ends with
*= is contains
~= is contains word
|= is starts with prefix (i.e., |= \"prefix\" matches \"prefix-...\")


回答2:

$(\'a[href$=\"ABC\"]:first\').attr(\'title\');

This will return the title of the first link that has a URL which ends with \"ABC\".



回答3:

$(\"a[href*=\'id=ABC\']\").addClass(\'active_jquery_menu\');


回答4:

$(\"a[href*=ABC]\").addClass(\'selected\');


标签: jquery string