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">
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.
Use JQuery selector $('a[href*=part_of_link]'). it will select the element if any part of the attribute matches with value.
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”).
$('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-...")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With