JSFiddle - React, Tailwind, and code Playground

by Ian Roberts

HTML

<img class="searchImagesBackground" />
<div class="searchImages" style="display:none;">
      <img src="http://placehold.it/101x101"/>
      <img src="http://placehold.it/102x102"/>
      <img src="http://placehold.it/103x103"/>
      <img src="http://placehold.it/104x104"/>
      <img src="http://placehold.it/105x105"/>
</div>

JavaScript

$(document).ready( function() {
    var imagesArr = $(".searchImages img").map(function() {
      return $(this).attr("src");
    });
    var loopImages = imagesArr.length;
    var x = Math.floor(loopImages*Math.random());
    $('.image').attr( 'src', imagesArr[x] );
});