tags:

views:

24

answers:

1

Hello,

I want to get all links that point to an image. Is there an easier way than the following?

$("a[href$=.jpg],a[href$=.jpeg],a[href$=.png]");

Thanks Jean

+3  A: 

You can use the .filter function:

$('a').filter(function() {
    return /\.(png|gif|jpg|jpeg)$/i.test(this.href);
});
David
you are right, vote to you :)
+1 Just make sure to test against the end of the string, so add a dollar sign: `/\.(png|gif|jpg|jpeg)$/`
Niels van der Rest
@Niels: Thanks.
David