Home >Web Front-end >JS Tutorial >Why Can't I Check My Radio Button with jQuery?
This article aims to provide solutions to the inability to check a radio button using jQuery in different scenarios.
In your current setup, you have provided a form containing three radio buttons with different IDs but sharing the same name attribute. However, none of the provided jQuery code appears to successfully check the radio button with the ID "radio_1."
To address this, consider the following solutions:
jQuery 1.6 and above:
For jQuery versions 1.6 and above, use the prop() method:
$("#radio_1").prop("checked", true);
jQuery prior to 1.6:
For jQuery versions prior to 1.6, use the attr('checked', 'checked') syntax:
$("#radio_1").attr('checked', 'checked');
Tip: Additionally, to ensure that the change is reflected in the DOM, you can call the click() or change() event on the radio button after setting the checked property.
The above is the detailed content of Why Can't I Check My Radio Button with jQuery?. For more information, please follow other related articles on the PHP Chinese website!