title: Rotating images between Divs
body: <p>I am trying to rotate some images inside some divs. Here's where I have reached so far with my limited jquery skills.</p>
  
  <pre><code>&lt;div id='pos-1'&gt;
  &lt;/div&gt;
  &lt;div id='pos-2'&gt;
  &lt;/div&gt;
  &lt;div id='pos-3'&gt;
  &lt;/div&gt;
  
  
  var image = new Array ();
    image[0] = "&lt;img src='https://placehold.it/200/09f/fff.png'/&gt;&lt;/a&gt;";
    image[1] = "&lt;img src='https://placehold.it/200/000/fff.png'/&gt;&lt;/a&gt;";
    image[2] = "&lt;img src='https://placehold.it/200/22f/000.png'/&gt;&lt;/a&gt;";
    image[3] = "&lt;img src='https://placehold.it/200/32f/fff.png'/&gt;&lt;/a&gt;";
    image[4] = "&lt;img src='https://placehold.it/200/42f/fff.png'/&gt;&lt;/a&gt;";
  
  var link = new Array ();
      link[0] = "&lt;a href='http://www.jquery.com'&gt;";
      link[1] = "&lt;a href='http://www.microsoft.com'&gt;";
      link[2] = "&lt;a href='http://www.yahoo.com'&gt;";
      link[3] = "&lt;a href='http://www.msn.com'&gt;";
      link[4] = "&lt;a href='http://www.stackoverflow.com'&gt;";
  
  var size = image.length;
  var x = Math.floor(size*Math.random());
  $('#pos-1').append(link[x]+image[x]);
  $('#pos-2').append(link[x]+image[x]);
  $('#pos-3').append(link[x]+image[x]);
  </code></pre>
  
  <p>Demo: <a href="https://jsfiddle.net/y0hga2of/" rel="nofollow noreferrer">https://jsfiddle.net/y0hga2of/</a></p>
  
  <p>Here the image is associated with the link so that once the user clicks on the div, he/she is taken to that url. Eg: image0 is associated with link0, image1 with link1 and so on.</p>
  
  <p>However with this code, the same image shows in all the divs. What I want is </p>
  
  <ul>
  <li>image0 and link0 should display in pos-1 </li>
  <li>image1/link1 and image2/link2 should 'rotate' in pos-2 </li>
  <li>image3/link3 and image4/link4 should rotate in pos-3</li>
  </ul>
  
  <p>Also currently I want to display only one image in pos-1. At a later stage, I may rotate two images as well in pos-1. Similarly I may display only one image in pos-2. How do I accommodate this flexibility in my code?</p>
  
  <p>Thanks.</p>