Pregunta

Hi I'm tearing my hair out with this code. Im trying to get it to only target my GIFS because the plugin is working on everything I post. I'm using HEADWAY and I have this in my footer.

<script>

jQuery(document).ready(function(){

  jQuery('body .post img').each(function(){

     // GET IMG SRC ATTR AS A STRING
     var GIFstr=jQuery(this).attr('src').toLowerCase();

     // IF STRING CONTAINS .GIF, ADD HYENA CLASS
     if( GIFstr.indexOf('.gif') )  jQuery(this).addClass('hyena');

  });

});

</script>

Im trying to get it to only target my GIFS because the plugin is working on everything post.

Thanks.

¿Fue útil?

Solución

You're not using indexOf() correctly.

// IF STRING CONTAINS .GIF, ADD HYENA CLASS
if( GIFstr.indexOf('.gif') !== -1 )  jQuery(this).addClass('hyena');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top