Skip to Content

Gareth53.co.uk - the online home of Gareth Senior

jQuery Selector: Attribute Filters

2:32p.m., Tue 27 Jan 2009

I just did a lazy thing. I decided I wanted all the links on my site that link to RSS feeds should have a relevant icon.

There's a link i the footer, which would have been easy to fix, but some bulleted links in body copy somewhere.

Two factors kick in at this point:

A) I couldn't be bothered to root out all the links within content

B) My TinyMC WYSIWG isn't best-suited to handle adding classes to links anyway.

So I used jQuery:

$("a[href$='.xml']").addClass("rss");

This attribute selector basically says: "all links that have a href attribute value that ends with .xml".

Which solves my problem.

The documentation is here.

Latest Posts

  • Muppets Birthday Card

    5:47p.m., 28 Nov

    Emma loves The Muppets. She even has her own Muppet who we call Emma Too and who was born at ...
  • Detecting Online Status In The Browser

    11:55a.m., 28 Nov

    I was just heading into a meeting when I was asked how our (mostly web-based) iOS application was going to ...
  • Dropping Support for Internet Explorer 6

    2:37p.m., 11 Oct

    Microsoft's Internet Explorer 6 has long been the bane of every front-end developer's life. It's a 10-year old browser - ...
  • Xfm Buzz - A Radio Hack

    1:15p.m., 31 May

    At Global Towers we developers have 10% time to go away and hack at something that might, ultimately, bring value ...

Blog Categories