I want to toggle a radio button on click, but it always return true, and not unchecked. I want to call a function when radio is checked and run another function when unchecked, how can I do this?
$('input[type="radio"]').click(function() {
console.log($(this).is(':checked'))
if ($(this).is(':checked')) {
$(this).attr('checked', false)
} else {
$(this).attr('checked', true)
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="radio" name="ch"/>
<input type="radio" name="ch"/>