Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Last active January 18, 2016 18:29
Show Gist options
  • Save ABM-Dan/595be28c5b3e28bb8070 to your computer and use it in GitHub Desktop.
Save ABM-Dan/595be28c5b3e28bb8070 to your computer and use it in GitHub Desktop.
// Implements a works-as-you-expect version of .change on radio buttons
(function ($) {
$.fn.onTrueChange = function (callable) {
return this.each(function () {
var caller = $(this);
caller.data('cached-value', caller.is(':checked'));
return caller.closest('form').find('input[name="' + caller.attr('name') + '"]').change(function(){
if (caller.is(':checked') != caller.data('cached-value')){
caller.data('cached-value', caller.is(':checked'));
callable.call(caller);
}
});
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment