title: How to Add id to each element based on the count in JQuery
body: <pre><code>&lt;div class="tile_nav"&gt;
  &lt;ul&gt;
  &lt;li&gt;&lt;span class="ullevel2"&gt;&lt;span&gt;Sample text&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
  &lt;li&gt;&lt;span class="ullevel2"&gt;&lt;span&gt;Sample text&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
  &lt;li&gt;&lt;span class="ullevel2"&gt;&lt;span&gt;Sample text&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
  &lt;li&gt;&lt;span class="ullevel2"&gt;&lt;span&gt;Sample text&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;        
  &lt;/ul&gt;   
  &lt;/div&gt;
  </code></pre>
  
  <p>I have used</p>
  
  <pre><code>$(".tile_nav .ullevel2 span").attr('id', function(index) {
  return "testDiv" + ($(this).index() + 1);
  });
  </code></pre>
  
  <p>How to add id to each element based on the length by jQuery each on page loading?
  <a href="https://jsfiddle.net/4LLocqau/1/" rel="nofollow">https://jsfiddle.net/4LLocqau/1/</a></p>