How to toggle between a still image and a gif from giphy api on click

430 Views Asked by At

I am trying to load a still image into the variable topicImage and then switch to the animated GIF when clicked. My code causes the image to disappear when clicked instead of switching to the animated GIF. Any input would be greatly appreciated.

            var topicImage = $("<img>");
            topicImage.attr("src", results[i].images.fixed_height_still.url);

            topicImage.on( "click", function() {
              topicImage.attr("src", results[i].images.fixed_height.url);
            });



            gifDiv.prepend(p);
            gifDiv.prepend(topicImage);

            $("#addedGifs").prepend(gifDiv);
          }
        });
            console.log(searchParam);
    });
0

There are 0 best solutions below