Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect .gif with jquery

I have a page with a lot of images. I want to hide those images only if they are gif.

this is the structure:

<div class="wrapper">
  <div class="entry">
     <div class="image"><img src="imagefile.png" /> </div>
   </div>
  <div class="entry">
     <div class="image"><img src="imagefile.gif" /> </div>
   </div>
</div>

I can filter All images this way:

$('.image').closest('.entry').not(".hidewrapper").wrap("<div class='hidewrapper' style=\"display:none\"></div>").closest('.entry').prepend("<a href=\"#\" class=\"unhideImage\" >show me</a>");

Because the site has a lot of images: Is there a way to filter only .gif - files WITHOUT a for-loop? Or am I just completely wrong that loops need much more performance than one-liners?

like image 346
Ole Albers Avatar asked Feb 08 '14 09:02

Ole Albers


2 Answers

you can detect it with,

$('div.image img[src$=".gif"]')

Please read here to know more about attribute ends with selector.

like image 60
Rajaprabhu Aravindasamy Avatar answered Oct 17 '22 08:10

Rajaprabhu Aravindasamy


You can use Attribute Ends With Selector [name$="value"]

$('.image img[src$=".gif"]')
like image 44
Satpal Avatar answered Oct 17 '22 08:10

Satpal