tags:

views:

16

answers:

1

Hi all. I want to add an event to my users clicking on file links (as opposed to links to internal or external pages). Is there a simple way to just get file links with a jquery selector? Or, do you think it's better to put a class on my file links and just select on the basis of that class?

thanks, max

+2  A: 

Use $ to get links having file extension:

$('a[href$=".pdf"]')

You can replace the .pdf with whatever file extension you want.

Sarfraz
Oooh... I'd never seen that one before. And here was me about to say you'd have to put classes on... :) That having been said I still think I'd advocate putting a class on since its much easier, especially if you have lots of different file types, etc. :)
Chris
@Chris: It is your choice :)
Sarfraz
ah yeah, that's cool. I guess that's the 'ends-with' selector? That is nice but after a bit of thought i'm going with putting classes on the links as it's more explicit. cheers tho :) max
Max Williams
@Max Williams: Yes it is end with selector and you are welcome :)
Sarfraz