title: Javascript: Array loop and outputting text
body: <p>How do I put the div id tag into an array an then output the image's alt text using a loop?</p>
  
  <p>For e.g., I have the following code...</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="imageGallery" style="left: 800px; position: absolute; top: 200px"&gt;
   &lt;center&gt;
    &lt;table border="0" cellspacing="0" cellpadding="3"&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;a href="#"&gt;&lt;img alt="Random Image 1" src="../Images/thumbnails/random1.jpg"
     style="border-color: #000000; border-width: 2px; border-style: ridge"&gt;&lt;/a&gt;&lt;/td&gt;
     &lt;td&gt;&lt;a href="#"&gt;&lt;img alt="Random Image 2" src="../Images/thumbnails/random2.jpg"
     style="border-color: #000000; border-width: 2px; border-style: ridge"&gt;&lt;/a&gt;&lt;/td&gt;
     &lt;td&gt;&lt;a href="#"&gt;&lt;img alt="Random Image 3" src="../Images/thumbnails/buckstb01.jpg"
     style="border-color: #000000; border-width: 2px; border-style: ridge"&gt;&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
    &lt;table border="0" cellspacing="0" cellpadding="3"&gt;
    &lt;tr&gt;
     &lt;td&gt;&lt;center&gt;&lt;a href="#"&gt;&lt;img alt="Random Image 4" src="../Images/thumbnails/portrait.jpg"
     style="border-color: #000000; border-width: 2px; border-style: ridge"&gt;&lt;/a&gt;&lt;/center&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
   &lt;/center&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I would like to put the id "imageGallery" into an array and output it's alt text afterwards.</p>
  
  <hr>
  
  <p>To Caius</p>
  
  <p>I've tried so many different variations.</p>
  
  <pre><code>var imageGallery = [ $( "#imageGallery img" ) ];
  
  for( i = 0; i &lt;= imageGallery.length; i++ )
  {
       $( "#imageGallery" ).attr( "alt" );
  }
  </code></pre>
  
  <p>Sometimes it would print out 1 letter at a time or just one set at a time, when I want the whole set.</p>
  
  <p>I can't remember if I did it this way as I tried so many different variations and forgot to save it as it didn't work.</p>