Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 208
Homer_J Avatar asked Nov 19 '25 13:11

Homer_J


2 Answers

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

Working Demo

 $("input:radio[class^=radio2]").each(function(i) {
like image 138
AnaMaria Avatar answered Nov 21 '25 03:11

AnaMaria


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/

like image 35
Anand Jha Avatar answered Nov 21 '25 01:11

Anand Jha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!