jeudi 26 mai 2016

Uncheck a checked radio on click [duplicate]

This question already has an answer here:

I want to create a radio button that can have an unchecked value. So I created the code:

$('form').on('click','input[type="radio"]:checked' ,function(event) {
    $(this).prop( "checked", false );
});

Well, this is pretty straightforward: click on a checked radio, uncheck it.

But, what happens is that it never checks the radio in the first place. When I click an unchecked radio it checks before detecting if is checked, then considers it checked and unchecks it.

How can I go arount this problem?




Aucun commentaire:

Enregistrer un commentaire