This should be the right code but its not working
<input type="radio" name="test">1
<input type="radio" name="test">2
$('input[name=test]').click(function() {
$('input[name=test]').attr(‘checked’,false);
});
example here
EDIT:
I forgot the line that should say if its checked then uncheck it
Change
.attrto.propand it will work fine. You will also need to change the quotes you are using around “checked” to be the right type, as that is also causing it to break at the moment:You can see this working in this example fiddle.
Update (based on comment)
Now that I actually understand what is required, a different approach is needed. You need to remember the previous value of the
checkedproperty, by storing it in an attribute:See this working here.
Update 2 (based on further comments)
The above code from the first update does not quite work, because when clicking a different radio button in the set, the
previousattribute of the previously checked radio remains set, but the radio is not actually checked. We can avoid this as follows: