Skip to content

Instantly share code, notes, and snippets.

@stiig
Created March 25, 2025 12:34
Show Gist options
  • Save stiig/d6c28416ad0ebb49968037d5f576b367 to your computer and use it in GitHub Desktop.
Save stiig/d6c28416ad0ebb49968037d5f576b367 to your computer and use it in GitHub Desktop.
Solution for making radio buttons uncheckable
$('.radio_with_uncheck').on('click', 'input[type="radio"]', function() {
var $radio = $(this);
var group = $('input[name="' + this.name + '"]');
if ($radio.prop('checked') && $radio.data('was-checked')) {
$radio.prop('checked', false);
}
group.data('was-checked', false);
$radio.data('was-checked', $radio.prop('checked'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment