We can use jQuery to set the value of a radio button to checked by making use of the jQuery prop() method. We simply need to change the checked property of the radio button to true. Here is how we can do this:

$("#radio-button").prop("checked",true);

If using WordPress, don’t forget to change the $ to jQuery:

jQuery("#radio-button").prop("checked",true);

Let’s see an example of this below.


Lets say we have the following HTML:

Select your favorite mode of transportation:

 





Set the radio button Airplane to checked

In this example, we will use the onclick event to call a function setRadio() which we will create below.

The setRadio() function will simply set the last radio button, Airplane, to be checked.

Here is our function using jQuery:

function setRadio(){
  $("#airplane").prop("checked",true);
}; 

Let’s try this out below:

Code Output:

Select your favorite mode of transportation:






Set the radio button Airplane to checked

Full Code:

Select your favorite mode of transportation:

 





Set the radio button Airplane to checked