How to find index based on sorted elements among siblings.?
<pre><code>&lt;div id="container"&gt;
  &lt;div class="aa"&gt;&lt;/div&gt;
  &lt;div class="bb"&gt;&lt;/div&gt;
  &lt;div class="aa"&gt;&lt;/div&gt;
  &lt;div class="bb"&gt;&lt;/div&gt;
  &lt;div class="bb"&gt;&lt;/div&gt;
  &lt;div class="bb"&gt;&lt;/div&gt;
  &lt;div class="bb"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>i just need to find the index of element based on particular class while looping.</p>

<p>Normal index will give the element index no: among the siblings.
I want to consider siblings with same class only, and give the index based on that sorted siblings.</p>

<pre><code>$("#container div").each(function(){

    if($(this).hasClass('bb')){
        var index = $(this).index();
            //will give me 1,3,4,5 etc

        //I want 0,1,2 etc ie: list the index based on class 

      }
    if($(this).hasClass('aa')){
           var index = $(this).index();

            //will give me 0 , 2
      //I want 0,1 etc ie: list the index based on class 
      }

})
</code></pre>
