dimanche 31 janvier 2021

jQuery function can 'check' but can't 'uncheck' checkboxes

I'm setting up a click event for a div that will check/uncheck a set of checkboxes with a given identifier. Everything I've tried will usually check the box but I haven't found any variation of the code that will uncheck it. Here's everything I tried so far:

var dtebox = $( "#tg" + did );
var stebox = $( "#tg" + sid );
dtebox.prop( "checked", !dtebox.prop("checked" ));
stebox.prop( "checked", !stebox.prop("checked" ));

if($( "#tg" + did ).checked){
    $( "#tg" + did ).prop( "checked", false );
    $( "#tg" + sid ).prop( "checked", false );
    setFilters();
}else{
    $( "#tg" + did ).prop( "checked", true );
    $( "#tg" + sid ).prop( "checked", true );
    setFilters();
}

if($( "#tg" + did ).is( ":checked" )){
    $( "#tg" + did ).prop( "checked", false );
    $( "#tg" + sid ).prop( "checked", false );
    setFilters();
}else{
    $( "#tg" + did ).prop( "checked", true );
    $( "#tg" + sid ).prop( "checked", true );
    setFilters();
}

if($( "#tg" + did ).prop("checked")){
    $( "#tg" + did ).prop( "checked", false );
    $( "#tg" + sid ).prop( "checked", false );
    setFilters();
}else{
    $( "#tg" + did ).prop( "checked", true );
    $( "#tg" + sid ).prop( "checked", true );
    setFilters();
}

I've also tried all of these variations with just one checkbox. I don't know if setting the checkbox to "false" negates the if statement but, based on all the similar posts I've seen, at least one of these methods should uncheck as well as check the boxes. Can anyone tell me why the uncheck doesn't work?




Aucun commentaire:

Enregistrer un commentaire