jQuery when all elements have a class do something
<p>I have any number of elements on a page with a class of choice e.g.</p>

<pre><code>&lt;div class="choice"&gt;&lt;/div&gt;
&lt;div class="choice"&gt;&lt;/div&gt;
</code></pre>

<p>When I run a function it adds a class of done to the the div so they become:</p>

<pre><code>&lt;div class="choice done"&gt;&lt;/div&gt;
</code></pre>

<p>Within this same function each time it runs I'm then going to check how many of those choices have the class of done on them and when they all have it I'm going to run another function.</p>

<p>This is what I have done so far:</p>

<pre><code>function addDone(element) {

$num = 0;

$(element).addClass('done');

$('.choice').each(function() {
    if($(this).hasClass('done')) {
        $num + 1;
    }
});

if($num &gt;= $('.choice').length) {
    alert('all done...');
}

}
</code></pre>

<p>But it runs the alert as soon as I call the function... so not working properly, any ideas on what the problem is or better solutions to do this?</p>

<p><strong>Note: That in the real app each choice has an id when is what goes in place of the element variable used in the function!</strong></p>
