1

I wanted to select all tags which points to an swf in jQuery. I wrote the following code and which works fine

$(a[href$=".swf"]).each( function(){
   alert('hello');
});

Now if i want to include SWF also for search, what is the best way?

Amit
  • 25,106
  • 25
  • 75
  • 116
  • [See this please](http://stackoverflow.com/questions/619621/how-do-i-use-jquery-to-ignore-case-when-selecting) – Sarfraz Feb 05 '10 at 08:30

3 Answers3

6

You may take a look at the filter function.

$('a').filter(function() {
    return (/\.swf$/i).test($(this).attr('href'));
}).each(function() {
    alert('hello');
});
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • +1, + maybe escape the dot. return (/\.swf$/i).test($(this).attr('href')); – Alex Feb 05 '10 at 08:37
  • Hey it worked.. cool... I Made it something like this $('a').filter(function() { var regexpr = /\.SWF$|\.PDF/i; if((regexpr).test($(this).attr('href'))) { alert($(this).attr('href')); } }); – Amit Feb 05 '10 at 09:01
1

For such a basic case, why not just do something like:

$('a[href$=".swf"], a[href$=".SWF"]').each( function(){
   alert('hello');
});

In general though, Darin has pointed you in the right direction.

No Surprises
  • 4,831
  • 2
  • 27
  • 27
0

If you are interested in .swf and .SWF, you can use this:

$('a[href$=".swf"], a[href$=".SWF"]').each( function(){
   alert('hello');
});
Fenton
  • 241,084
  • 71
  • 387
  • 401