tags:

views:

42

answers:

4

Hi,

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?

+4  A: 

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, + maybe escape the dot. return (/\.swf$/i).test($(this).attr('href'));
Alex
@Alex, thanks for pointing this out. I've updated my answer.
Darin Dimitrov
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
+1  A: 

See this please

Sarfraz
A: 

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

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

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