Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select <a> which href ends with some string

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">

like image 428
Aximili Avatar asked Nov 20 '08 00:11

Aximili


People also ask

How do you check if a href contains a string?

To check if the current URL contains a string in Javascript, you can apply the “test()” method along with the “window. location. href” property for matching the particular string value with the URL or the “toString(). includes()”, or the “indexOf()” method to return the index of the first value in the specified string.

How do you select a href element?

Use JQuery selector $('a[href*=part_of_link]'). it will select the element if any part of the attribute matches with value.

What would be selector that you would use to select all hyperlinks whose href attribute's value ends with DOCX?

Similar to the “begins with” selector, the “ends with” selector allows for the selection of elements where a specified attribute (e.g. the href attribute of a hyperlink) ends with a specified string (e.g. “. pdf”, “. docx” or “. mp3”).


1 Answers

   $('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-...") 
like image 136
tvanfosson Avatar answered Sep 18 '22 17:09

tvanfosson