4

I want this functionality:

When user clicks on already checked radio button, it should uncheck it.

I'm trying this code but no luck.

$(document).on('mouseup','className',function(){
    if ($(this).is(':checked')){
        $(this).prop('checked', false);
    }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
user3484291
  • 217
  • 2
  • 7
  • 1
    Duplicate? http://stackoverflow.com/questions/2117538/jquery-how-to-uncheck-a-radio-button – Eddie Apr 01 '14 at 09:12

4 Answers4

7

You can try

$(document).on('dblclick','.className',function(){
    if(this.checked){
        $(this).prop('checked', false);
    }
});

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
1

Try This

HTML

<input type="radio" class="rdCheck" checked="checked" text="click me"/> click me

JS

$('.rdCheck').dblclick(function(){

          if($(this).is(':checked'))
          {
             $(this).removeAttr('checked');
          }
});

DEMO HERE

Kiranramchandran
  • 2,094
  • 16
  • 30
0

You can use .dblclick():

$(document).on('dblclick','className',function(){
    if ($(this).is(':checked')){
        $(this).prop('checked', false);
    }
});
Felix
  • 37,892
  • 8
  • 43
  • 55
0

I think this way:

$(document).on('dblclick','.yourCls',function(){
   if(this.checked){ // if true
      $(this).prop('checked', !this.checked); // then !this.checked == false
   }
});

Well you have to check for its checked state this.checked returns boolean values true/false. if true the uncheck it or else check it.

Jai
  • 74,255
  • 12
  • 74
  • 103