Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery plugin to allow unchecking radio buttons
(function ($) {
$.fn.uncheckableRadio = function () {
return this.each(function () {
var radio = this,
label = $('label[for="' + radio.id + '"]');
if (label.length === 0) {
label = $(radio).closest("label");
}
var label_radio = label.add(radio);
label_radio.mousedown(function () {
$(radio).data('wasChecked', radio.checked);
});
label_radio.click(function () {
if ($(radio).data('wasChecked')) {
radio.checked = false;
}
});
});
};
})(jQuery);
@kdimatteo

This comment has been minimized.

Copy link

@kdimatteo kdimatteo commented Apr 22, 2014

This is great, added a bower repo for jquery-uncheckable-radio for prod. use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.