vendredi 5 avril 2019

Can't select a checkbox with jQuery

I have this HTML

<label class="">
    <label>
        <input type="checkbox" class="selectAll" name="RAT_RoomsAffected">
        Activate
    </label>
</label> 

<br />

<label class="">
    <label>
        <input type="checkbox" name="RAT_RoomsList[]" value="75" checked="">
        <div style="width: 200px">Room #1</div>
    </label>
</label>

<label class="">
    <label>
        <input type="checkbox" name="RAT_RoomsList[]" value="76" checked="">
        <div style="width: 200px">Room #2</div>
    </label>
</label>

And here's my try:

if($('.selectAll').length) {
    $('.selectAll').click(function() {
        if ($(this).prop("checked", true)) {
            $('input[type=checkbox]').not('.selectAll').each(function() {
                this.checked = false;
            });
        }
    });
    $('input[type=checkbox]').not('.selectAll').click(function() {
        if ($(this).prop("checked", true)) {
            $('.selectAll').prop("checked", false);
        }
    });
}

Actually, my problem is I can't click on the Room #1 and Room #2 checkboxes.

I think I'm very near of the solution but I can't make it work actually.

Do you know why please ?

Thanks.




Aucun commentaire:

Enregistrer un commentaire