jQuery check/uncheck radio button onclick I have this code to check/uncheck a radio button onclick. I know it is not good for the UI, but I need this. $('#radioinstant').click(function() { var checked = $(this).attr('checked', true); if(checked){ $(this).attr('checked', false); } else{ $(this).attr('checked', true); } }); The above function is not working. If I click on the button, nothing changes. It remain checked. Why? Where is the error? I am not a jQuery expert. I am on jQuery 1.3.2 Just to be clear #radioinstant is the ID
undefined
How do I check/uncheck a checkbox input or radio button? How do I check/uncheck a checkbox input or radio button? Just simple you use, check or uncheck a checkbox element or a radio button using the .prop() method: // Check #x $( "#x" ).prop( "checked", true ); // Uncheck #x $( "#x" ).prop( "checked", false ); source form : https://learn.jquery.com/using-jquery-core/faq/how-do-i-check-uncheck-a-checkbox-input-or-radio-button/