jQuery .each() does not update
<p>I am trying to check if a set of radio buttons has been selected. However, it seems that it does not update if a radio is selected after the fact. </p>

<p>The code:</p>

<pre><code>$('button#submit').click(function() {
    var addr_chkd = 0;
    $('input:radio[name="address"]').each(function() { 
        if (!$(this).attr('checked'))
            addr_chkd++
    });
});

if (addr_chkd)
    // do something
</code></pre>

<p>When the button is clicked and nothing is selected, the code works great. However, when a radio button is selected and the button is clicked, <code>addr_chkd</code> still returns a value greater than zero.</p>

<p><strong>[UPDATE]</strong></p>

<p>The issue is that I'm checking for <code>addr_chkd</code> greater than zero. I should be checking if <code>addr_chkd</code> is equal to the length of the radio buttons. I made a slight modification to @PPvG's answer and it did the trick.</p>

<pre><code>$('button#submit').click(function() {
    var radios = $('input:radio[name="address"]');
    var num_unchecked = radios.filter(':not(:checked)').length;
    if (num_unchecked === radios.length) {
        alert('please select a button');
    }
});
</code></pre>
