I have a code which counts the checked checkboxes. It works fine when selecting, but the count breaks (adds +1 to the count) when i deselect some of the already selected checkboxes.
HTML:
<div>Number of checkboxes checked: <span id='chck'>0</span></div>
<table>
<tr><td><input type='checkbox' /></td></tr>
<tr><td><input type='checkbox' /></td></tr>
<tr><td><input type='checkbox' /></td></tr>
<tr><td><input type='checkbox' /></td></tr>
<tr><td><input type='checkbox' /></td></tr>
<tr><td><input type='checkbox' /></td></tr>
<tr><td><input type='checkbox' /></td></tr>
</table>
JS:
$('tr :checkbox').change(function(){
$('#chck').text($(this).add(':checked').length);
});
FIDDLE: http://jsfiddle.net/kAsxj/