twitter/bootstrap — Issue #742: Suggested add-on checkbox logic is poor.
Author: KendallHopkins
Created: 2011-12-02 18:23:50+00:00
State: open

In `application.js` it's suggested that to keep the `active` on the checkbox they should use the following code:

$('.add-on :checkbox').click(function () {
if ($(this).attr('checked')) {
$(this).parents('.add-on').addClass('active')
} else {
$(this).parents('.add-on').removeClass('active')
}
})

This doesn't handle the problem if they are out-of-sync on page load (pre-checked). It also uses an incorrect way of checking for `checked` state of the checkbox.

I would suggest:

syncCheckBox = function() {
$(this).parents('.add-on').toggleClass('active', $(this).is(':checked'));
};
return $('.add-on :checkbox').each(syncCheckBox).click(syncCheckBox);