Question

Is it possible to uncheck a radio button based on class?

$('#button').click(function () {

    $("input:radio[class^='.radio2']").each(function(i) {
      this.checked = false;
        });

});

JsFiddle = http://jsfiddle.net/nPgyd/1/

This doesn't appear to work.

Was it helpful?

Solution

HERE is your solution. You only need to remove the braces to compare the class

Working Demo

 $("input:radio[class^=radio2]").each(function(i) {

OTHER TIPS

Try

Fiddle Demo

$('#button').click(function () {

    $(".radio2").each(function(i) 
     {
          this.checked = false;
     });

});

This might be helpful for you.

$('#button').click(function () {
    $("input:radio.radio2").each(function(i) {
            $(this).attr('checked',false);
    });

});

Check the link...

http://jsfiddle.net/nPgyd/13/

Yes you can, the syntax required is not nearly as complex as that.

$('#button').click(function () 
{    
    $(".radio2").each(function(i) 
    {
          this.checked = false;
    });                
});

Or if you want only inputs with the class radio2 to be affected:

$('#button').click(function () 
{    
    $("input.radio2").each(function(i) 
    {
          this.checked = false;
    });                
});

jsFiddle demo

Try something like this?

$('#button').click(function () {

    $("input[type='radio'].radio2").each(function () {
        $(this).prop('checked', false);
    });

});

jsFiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top