JQuery - If value = "test" is unchecked

I am trying to use jQuery to clear the checkbox if the value is equal to a variable, for example, "test" Example:

<input type="checkbox" name="cbname" value="test" checked="checked" />

Since this has a test value, I would like it to be uncorked, how could I do this?

thanks

+4
source share
3 answers
 var val = 'test'; $('input:checkbox[value="' + val + '"]').attr('checked', false); 
+10
source
 var checkForInstance = function (myCheckbox,myInstance) { if (jQuery('#'.myCheckbox).is(":checked") && jQuery('#'+myCheckbox).val() == jQuery('#'+myInstance).val() ) { jQuery('#'.myCheckbox).attr('checked',false); } } 

this function checks if your checkbox value matches a different value for the elements and cancels it if checked.

0
source

Use prop in jquery 1.9.1

 var value = 'test'; $('input:checkbox[value="' + value + '"]').prop('checked', false); 
0
source

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


All Articles