title: How to generate dynamic id using jQuery?
body: <p>I want to add progressive id to a series of elements on an unordered HTML list. I used the jQuery <code>.each()</code> method to get each <code>&lt;li&gt;</code> of the List and append a <code>&lt;span&gt;</code> inside each <code>&lt;li&gt;</code>. Then I added the ID attribute with index of each() as number.</p>
  
  <pre><code>$('#menu li ul li').each(function(i, e){
      $(this).append('&lt;span class="arr"&gt;&lt;/span&gt;');
      $(".arr").attr("id", "id_" + i);
  });
  </code></pre>
  
  <p><kbd><a href="http://jsfiddle.net/NZgyD/" rel="noreferrer"><strong>Fiddle Demo</strong></a></kbd></p>
  
  <p>But I get <code>id_3</code> for all elements. Why? What did I do wrong?</p>
  
  <p>Thanks for any help!</p>