How to check a radio button with jQuery?
Last Updated :
03 Aug, 2021
There are two methods by which one can dynamically change the currently selected radio button by changing the checked property of the input type.
Method 1: Using prop method: The input can be accessed and its property can be set by using the prop method. This method manipulates the 'checked' property and sets it to true or false depending on whether we want to check or uncheck it.
Syntax:
$("element").prop("checked", true)
Example:
html
<!DOCTYPE html>
<head>
<title>
How to check a radio button
with jQuery?
</title>
<script src=
"https://code.jquery.com/jquery-2.2.4.min.js">
</script>
</head>
<body>
<h1 style="color: green">
GeeksForGeeks
</h1>
<b>
jQuery Check/Uncheck Radio Button
</b>
<p>
<input type="radio" name="option" id="free">
Free Membership
<input type="radio" name="option" id="premium">
Premium Membership
</p>
<p>
<button type="button" class="check-free">
Get Free
</button>
<button type="button" class="check-premium">
Get Premium
</button>
<button type="button" class="reset">
Reset options
</button>
</p>
<script type="text/javascript">
$(document).ready(function () {
$(".check-free").click(function () {
$("#free").prop("checked", true);
});
$(".check-premium").click(function () {
$("#premium").prop("checked", true);
});
$(".reset").click(function () {
$("#free").prop("checked", false);
$("#premium").prop("checked", false);
});
});
</script>
</body>
</html>
Output:
- Clicking on the 'Get Free' button:

- Clicking on the 'Get Premium' button:

- Clicking on the 'Reset options' button:

Method 2: Using attr method: It is similar to the above method and more suitable for older jQuery versions. The input can be accessed and its property can be set by using the attr method. We have to manipulate the 'checked' property and set it to true or false depending on whether we want to check or uncheck it.
Note: It is necessary to add a click method when setting the attribute to 'true' to make sure that the option gets updated in the option group.
Syntax:
$("element").attr("checked", true)
Example:
html
<!DOCTYPE html>
<head>
<title>
How to check a radio
button with jQuery?
</title>
<script src=
"https://code.jquery.com/jquery-2.2.4.min.js">
</script>
</head>
<body>
<h1 style="color: green">
GeeksForGeeks
</h1>
<b>jQuery Check/Uncheck Radio Button</b>
<p>
<input type="radio" name="option" id="free">
Free Membership
<input type="radio" name="option" id="premium">
Premium Membership
</p>
<p>
<button type="button" class="check-free">
Get Free
</button>
<button type="button" class="check-premium">
Get Premium
</button>
<button type="button" class="reset">
Reset options
</button>
</p>
<script type="text/javascript">
$(document).ready(function () {
$(".check-free").click(function () {
$("#free").attr("checked", true).click();
});
$(".check-premium").click(function () {
$("#premium").attr("checked", true).click();
});
$(".reset").click(function () {
$("#free").attr("checked", false);
$("#premium").attr("checked", false);
});
});
</script>
</body>
</html>
Output:
- Clicking on the 'Get Free' button:

- Clicking on the 'Get Premium' button:

- Clicking on the 'Reset options' button:

jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it's philosophy of “Write less, do more".
You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.
Similar Reads
How to check whether a radio button is selected with JavaScript ? Here are the different methods used to check the radio button is selected:1. Using Input Radio checked propertyThe checked property in JavaScript checks if a radio button is selected. By using document.getElementById or querySelector to get the radio button, the checked property returns true if the
3 min read
How to make a Themed Radio Button using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Themed Radio Button using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesheet
1 min read
How to know which radio button is selected using jQuery? To check which radio button is selected in a form, we first get the desired input group with the type of input as an option and then the value of this selection can then be accessed by the val() method. This returns the name of the option that is currently selected. The selector 'input[name=option]:
2 min read
How to unchecked a radio button using JavaScript/jQuery? In order to uncheck a radio button, there are a lot of methods available, but we are going to see the most preferred methods. In HTML, we can create radio buttons using the same name attribute, and by setting a unique value for each radio button within the group. Only one radio button within the gro
2 min read
How to make a Mini size Radio Button using jQuery Mobile ? jQuery Mobile is a web-based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Mini size Radio Button using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesh
1 min read