checkbox new state not reflecting
<p>I also updated problem at <a href="http://jsfiddle.net/7ZpCW/1/" rel="nofollow">http://jsfiddle.net/7ZpCW/1/</a></p>

<p>I have implemented the code such that when i click on checkbox or text next to it , checkbox should be selected/de-selected depending upon its previous state.</p>

<p>Problem is when i click on text , though checkbox is getting checked but the alert message is getting executed only the number of times the previous checkboxes were selected </p>

<p>while when i click on checkbox alert message is executed based on current state.</p>

<p>Please help</p>

<p><img src="http://i.stack.imgur.com/4vfIM.png" alt="enter image description here"></p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;span id="MYARRAYloader_collapse" class = "w195"  style="display:block"&gt;
&lt;div class="sp15"&gt;&amp;nbsp;&lt;/div&gt;

&lt;div class="lf  fs12 lh15" style="padding-left:10px;"&gt;
&lt;input type="checkbox" name="MYARRAY[]" id="MYARRAY0"  value="ALL"  checked  class="chbx checkbox-selector1"&gt;
&lt;a href="#" class="checkbox-selector" style="color:#5B5B5B;"&gt;All&lt;/a&gt; 
&lt;br&gt;
&lt;input type="checkbox" name="MYARRAY[]"  value="V"  class="chbx checkbox-selector1"&gt;
&lt;a href="#" class="checkbox-selector" style="color:#5B5B5B;"&gt;Opt1&lt;/a&gt; 
&lt;span class="gray t11"&gt;(42)&lt;/span&gt;
&lt;br&gt;
&lt;input type="checkbox" name="MYARRAY[]"  value="N"  class="chbx checkbox-selector1"&gt;
&lt;a href="#" class="checkbox-selector" style="color:#5B5B5B;"&gt;Opt2&lt;/a&gt; 
&lt;span class="gray t11"&gt;(38)&lt;/span&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;div class="sp12"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/span&gt;

&lt;script&gt;
$('.checkbox-selector').click(function() {
var chb = $(this).prev();
chb.click();
return false;
})
$('.checkbox-selector1').click(function() {
var chb , chb1 , action;
chb= $(this); 
clusterName = chb.attr('name');
clusterVal = chb.attr('value');

var array = new Array();


$('input[name="'+clusterName+'"]:checked').each(function(i,el){
alert('Count Me');
chb1 = $(this); 

if(clusterVal == 'ALL')
{
if(chb1.attr('value')!='ALL')
{
chb1.attr("checked","");
}
else
array.push($(el).val());
}
else
{
if(chb1.attr('value')=='ALL')
{
chb1.attr("checked","");
}
else
{
array.push($(el).val());
}
}
});

});
&lt;/script&gt;
</code></pre>
