Simple jQuery code snippets to set and unset input values on radio buttons. Just thought I would share because I was having a few issues with earlier versions of jQuery and setting radio buttons on a form.

//jQuery Set Radio Button
$('input[name="correctAnswer"]').attr('checked', false);

//To unselect the button

//jQuery (1.4+) code to pre-select one button :
var presetValue = "black";
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

  • Kalana Nissanka

    Q1. Is there any way to create the label of the radio button dynamically?

    Q2. How can we get the checked value from a radio button group?

    • jquery4u

      Hi Kalana,

      1. Yes you can create a label element and insert it before the radio button like so (not tested):

      var labelText = $(‘#radioBtnId’).attr(‘name’);

      2. Try this:


      or when it is selected try:

      $(“input:radio[name=theme]”).click(function() {
      var value = $(this).val();


Ending Soon
Free SitePoint Premium

Get one free year of unlimited book and course downloads on SitePoint Premium!