Today I was trying to figure out a way to apply some functionality to a given set of anchor tags on a web page. Basically, I wanted to be able to add a function to all of the anchor tags on a page that link to an image file. The first thing that came to mind for how to handle this, was jQuery. It was made for this sort of thing. I knew I could do it with jQuery, it just took me a little bit to figure out the right syntax for doing it. So, I had to figure out a way to write a jQuery selector that said “give me all of the anchor tags on the page where the href attribute contains an image file extension”. So I did a little bit of searching, and stumbled across this article on how to use predicate selectors in jQuery. The syntax I ended up with was:
1: $(“a[@href *= '.jpg']“)
BRILLIANT! (yes, I know, I still need to figure out how to OR the other image type extensions (.gif, .png, etc) together into the “contains” predicate, but that’s the easy part really). I couldn’t put it any more clearly than, or agree with this statement any more (pardon the language):
The more I read up on jQuery, the more I realize how sweet-a** it is. jQuery is the “Easy” button of the user interface world.
That says it all for me right there. Before I was introduced to jQuery, I hated doing JavaScript of any kind in my web apps. Now, having jQuery, I go out of my way to look for ways to use it…its THAT cool.







