3

I need to find (and hide) all links with images (.jpg, .png, .gif) in href as they're causing my wordpress excerpts to break.

Many thanks.

eozzy
  • 66,048
  • 104
  • 272
  • 428

2 Answers2

13
$('a').filter(function() {
    return $(this).attr('href').match(/\.(jpg|png|gif)/i);
}).hide();
David Hellsing
  • 106,495
  • 44
  • 176
  • 212
  • It also would work in some edge cases like image1.jpg&uname=tom ... however in saying that it would also match the extension if it occurred as part of the URL elsewhere... but that seems unlikely. – alex Dec 01 '09 at 14:04
3

Okay, figured it :P

$("a[href$='.jpg']").addClass('hide');
eozzy
  • 66,048
  • 104
  • 272
  • 428
  • 2
    You could instead call `.hide()` if you'd rather. – Glen Solsberry Dec 01 '09 at 13:56
  • You should consider for .jpg , .jpeg , .JPG and .JPEG Having David example to be case insensitive, and adding jpeg, should to the trick. (I'm not good with regex to write a proper answer, sorry) – Omiod Dec 01 '09 at 23:34