Homer_J
Homer_J

Reputation: 3323

jQuery uncheck radio button based on class

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.

Upvotes: 3

Views: 8342

Answers (5)

Shivam
Shivam

Reputation: 2248

Try something like this?

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

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

});

jsFiddle

Upvotes: 0

Anand Jha
Anand Jha

Reputation: 10724

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/

Upvotes: 2

Dolchio
Dolchio

Reputation: 467

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

Upvotes: 0

Tomas Santos
Tomas Santos

Reputation: 550

Try

Fiddle Demo

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

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

});

Upvotes: 1

AnaMaria
AnaMaria

Reputation: 3621

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

Working Demo

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

Upvotes: 5

Related Questions