Detect .gif with jquery

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

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>");

Since there are a lot of images on the site: is there a way to filter only .gif files WITHOUT a loop? Or am I just completely wrong that loops need much more performance than single-line ones?

+4
source share
2 answers

you can detect it with

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

Read here to learn more about attribute ends with selector.

+4
source

[name $= "value" ]

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

Source: https://habr.com/ru/post/1525916/


All Articles