title: Storing DOM reference elements in a Javascript array
body: <p>Dear experts, I was trying to dynamically generate DOM elements using JS.</p>
  
  <p>I read from Douglas Crockford's book that DOM is very very poorly structured. </p>
  
  <p>Anyways, I would like to create a number of DIVISION elements and store the reference into an array so it could be accessed later. </p>
  
  <p>Here's the code</p>
  
  <pre><code>for(i=0; i&lt;3; i++) {
      var div = document.body.appendChild(document.createElement("div"));
      var arr = new Array();
      arr.push(div);
  }
  </code></pre>
  
  <p>Somehow this would not work.....
  There is only 1 div element created.
  When I use the <code>arr.length</code> to test the code there is only 1 element in the array.</p>
  
  <p>Is there another way to accomplish this?</p>
  
  <p>Thanks in advance</p>