Created
March 11, 2014 11:42
-
-
Save eikes/9484101 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
This is great, added a bower repo for
jquery-uncheckable-radio
for prod. use.