jQuery(function($) { $(document).on('mouseover', '.vp-portfolio__item-img img', function() { var $this = $(this); // save old image. $this.attr({ 'data-saved-src': $this.attr('src'), 'data-saved-srcset': $this.attr('srcset'), }); // add gif. $this.attr({ src: 'https://www.lumapod.com/wp-content/uploads/20_Slide_10fps.gif', srcset: '', }); }); $(document).on('mouseout', '.vp-portfolio__item-img img', function() { var $this = $(this); // restore image. if ( $this.attr('data-saved-src') ) { $this.attr({ src: $this.attr('data-saved-src'), srcset: $this.attr('data-saved-srcset'), }); $this.removeAttr('data-saved-src'); $this.removeAttr('data-saved-srcset'); } }); });

Test