jQuery 1.8.2 | Counter for both user-click and dynamically checked dynamically inserted checkboxes.

jQuery 1.8.2 | Counter for both user-click and dynamically checked dynamically inserted checkboxes.

The following code works for user-click event on dynamically inserted class-based checkboxes:

  1. $('.aenable, .benable').live('change', function() {
  2. var chkbxchkd = $('.aenable:checkbox:checked, .benable:checkbox:checked').length; 
  3. $('.counter').html('( ' + chkbxchkd + ' selected )');
  4. });

The problem is when I click on a button that toggles on and off the checked states of the class-based dynamically inserted checkboxes, the counter doesn't reflect the actual number of checked checkboxes. Basically, I need a live counter that constantly detects (and counts) user-clicked and dynamically checked or unchecked dynamically inserted class-based checkboxes. Any hint? - dan