jQuery Filtering Tip
I was adding some jQuery to a sight I’m working on, code that would append the little “External Link” icon to a link, when I discovered a small problem. The code would, quite naturally, append the icon to links that were images themselves. After a few minutes of digging around and trying different filters, this is what I came up with:
$(‘a’).not(‘:has(img)’)
:has looks for a matching selector, in this case img, if it finds img in a link it then returns true to .not() which in turn says skip this link.
Some of you probably already knew that, but for those that didn’t I thought I’d pass it along.

Add A Comment