title: Placing elements within a container div into an array - jQuery or JavaScript
body: <p>I have a div that contains a number of Instagram images, produced by the instafeed.js plugin. After running the plugin, the resultant HTML looks like this:</p>
  
  <pre><code>&lt;div id="instafeed"&gt;
      &lt;a&gt;&lt;img /&gt;&lt;/a&gt;
      &lt;a&gt;&lt;img /&gt;&lt;/a&gt;
      &lt;a&gt;&lt;img /&gt;&lt;/a&gt;
      etc...
  &lt;/div&gt;
  </code></pre>
  
  <p>I am trying to find a way to load the contents of this div into an array; I believe that the easiest way would be to just take the  tags, which is fine.</p>
  
  <p>I'm pretty inexperienced with both JS and jQuery, which is why I'm having difficulty achieving this and I've not been able to find any forum posts that quite do what I'm hoping to achieve.</p>
  
  <p>So far, all I'm trying to do is load the contents of the div into an array and print it back out to the document, which should (in my mind anyway) add the  tags back into the HTML. I'm trying with both JavaScript and jQuery and having little success with either. I'd appreciate any thoughts:</p>
  
  <p>JS:</p>
  
  <pre><code>var containerDiv = document.getElementById('instafeed');
  var pics = containerDiv.getElementsByTagName('img');
  
  console.log(pics); //Tells me at least that I have an array of img
  
  for (var i = 0; i &lt; pics.length; i++) {
      document.write(pics[i]);
  } //Seemingly does nothing
  </code></pre>
  
  <p>jQuery:
  (I'm really sorry if this code is just all wrong, I really don't know jQuery very well at all)</p>
  
  <pre><code>$(document).ready(function() {
      var pics = [];
  
      $('#instafeed').find('img').each(function() {
          pics.push($(this));
      });
  
      for (i = 0; i &lt; pics.length; i++) {
          console.log(pics[i]);
      }
  
  });
  </code></pre>
  
  <p>Any thoughts, tips or pointers would be much appreciated.</p>
  
  <p>Edit:
  Just to add a little background to my problem, to avoid causing any more confusion.</p>
  
  <p>I'm trying to pull four random images from a user-specific Instagram feed for display on a website. instafeed.js can pull just four images and it can randomise the images, but Instagram itself always sends the four most recent images, so the plugin is just randomising the order of the same four pictures each time.</p>
  
  <p>I'm trying to let the plugin send through every picture, which will go into the div instafeed. From here I want to load all of the contained images into an array so that I can randomly pick four images for display on the site.</p>