Check this code: https://github.com/rmariuzzo/checkboxes.js/blob/master/src/jquery.checkboxes.js#L136