If you want to check a radio button when it's unchecked and uncheck it when it's checked, there's a catch. As soon as you click on the input, the value is set to true, so the expected behaviour cannot be achieved. So first you have to block the action of the click, then use the "mousedown" and "mouseup" events to stealthily detect the state of the input. Idem for label
https://jsfiddle.net/greatalf/k7cwfemp/4/
<!DOCTYPE html>
<html>
<head>
<title>Uncheck radio button</title>
</head>
<body>
<input type="radio" name="options" value="option1" id="option1">
<label for="option1">Option 1</label><br>
<input type="radio" name="options" value="option2" id="option2">
<label for="option2">Option 2</label><br>
<input type="radio" name="options" value="option3" id="option3">
<label for="option3">Option 3</label><br>
</body>
</html>
$('label').click(function(e) {
e.preventDefault()
var inputId = '#' + $(this).attr("for");
if( $(inputId).prop("checked") === true )
{
$(inputId).prop("checked", false);
}
else {
$(inputId).prop("checked", true);
}
});
$('input[type="radio"]').on('click', function(e) {
e.preventDefault()
})
$('input[type="radio"]').on('mousedown', function(e) {
if( $(this).prop("checked") === true )
{
$(this).prop("checked", false);
}
else {
$(this).prop("checked", true);
}
});
$('input[type="radio"]').on('mouseup', function(e) {
if( $(this).prop("checked") === false )
{
$(this).prop("checked", false);
}
});