-
-
Save exside/8890792b4c308b8b04962f5600603abd to your computer and use it in GitHub Desktop.
jQuery plugin to allow unchecking radio buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment