How can I count the total amount of elements inside an each function?
<p>Inside my each function I am pulling text from a div, adding it as a class to a parent element, and then I need to count how many elements have that class. The problem comes in because it's inside my each function as it counts up incrementally instead of just giving me the total amount. </p>

<p>You can see in my fiddle that the output is 1231211 and what I'm trying to get is 3211. </p>

<p><a href="http://jsfiddle.net/KqcWh/" rel="nofollow">My Fiddle</a></p>

<p>My HTML</p>

<pre><code>&lt;div class="parent"&gt;
    &lt;div class="nid"&gt;asdf&lt;/div&gt;
&lt;/div&gt;

&lt;div class="parent"&gt;
    &lt;div class="nid"&gt;asdf&lt;/div&gt;
&lt;/div&gt;

&lt;div class="parent"&gt;
    &lt;div class="nid"&gt;asdf&lt;/div&gt;
&lt;/div&gt;

&lt;div class="parent"&gt;
    &lt;div class="nid"&gt;qwerty&lt;/div&gt;
&lt;/div&gt;

&lt;div class="parent"&gt;
    &lt;div class="nid"&gt;qwerty&lt;/div&gt;
&lt;/div&gt;

&lt;div class="parent"&gt;
    &lt;div class="nid"&gt;zxcv&lt;/div&gt;
&lt;/div&gt;

&lt;div class="parent"&gt;
    &lt;div class="nid"&gt;ghjk&lt;/div&gt;
&lt;/div&gt;

&lt;div class="numbers"&gt;

&lt;/div&gt;
</code></pre>

<p>My jQuery</p>

<pre><code>$(".nid").each(function() {
    var nid = $(this).text();
    $(this).parent().addClass(nid);
    var nidCount = $(".parent."+nid).length;
    $('.numbers').append(nidCount);
});
</code></pre>
