title: Assign Id's dynamically to DOM elements with javascript
body: <p>I just have a quick question about how to generate id's on-the-fly for HTML elements.
  So far I've tried a few things, I started with a "for" loop, I already know how many elements I have to generate Id's for, in this case I have an "ul" with 6 "li".
  My "for" loop is as follows:</p>
  
  <pre><code>var items = $("ul li").length;
  for(var i = 0; i &lt;= items; i++){
      $("ul li").attr("id", "number" + i);
  }
  </code></pre>
  
  <p>"number" would be the new id concatenated with "i", so I get a different Id for each "li".
  As you can probably tell, this does not work, because I end up with the same Id for each "li": </p>
  
  <p>in this case I get <code>&lt;li id="number6"&gt;... &lt;/li&gt;</code> for all the "li" elments in the "ul".
  I tried a "while" loop and ".each()" with jQuery but I get the exact same thing.</p>
  
  <p>Any help would be appreciated.</p>