Search code examples
jqueryhyperlinktraversal

How to find links with a specific extension using jQuery


I am trying to traverse and find links with a specific extension (*.ashx) so that I can open the link in a new tab. (Sitefinity does not allow target="_blank").

I can find the tags using jQuery, but I need to then filter it more so that when I click on an tag with an extension of .ashx, I can open this in a new window.

Something like this

<a href="anniversary.sflb.ashx"> Anniversary </a> 

Many thanks, James


Solution

  • It would be better to use the attribute contains selector

    $("a[href*='.ashx']").each(
      function() {
      //Do stuff
    });
    

    see http://jsfiddle.net/graham/Fa6kV/