How to uncheck the box when double-clicking?

I want this functionality:

When the user clicks on an already installed switch, he must turn it off.

I am trying to use this code but no luck.

$(document).on('mouseup','className',function(){
    if ($(this).is(':checked')){
        $(this).prop('checked', false);
    }
});
+4
source share
4 answers

You can try

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

Demo: Fiddle

+6
source

try it

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

+1
source

You can use . dblclick () :

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

I think so:

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

Well, you need to check its check status this.checkedreturns boolean values true/false. if trueuncheck or check it.

0
source

Source: https://habr.com/ru/post/1534392/


All Articles