vendredi 13 août 2021

If and else statments

So basically I am trying to create an if/else statement for buttons for example. When none of the checkboxes are checked I want to display the disabled button, but when 1 or more checkbox are checked I want to display another button.

Js

 $("#checkAll").change(function () {
        $("input:checkbox").prop('checked', $(this).prop("checked"));
    });

Html

 <input type="checkbox" id="checkAll" style="margin-left:-10px" />
 <input type="checkbox"  style="margin-left:5px" />
 <input type="checkbox"  style="margin-left:5px" />


<div class="ml-2">
               if(checked){
                <button type="button" class="btn btn-danger ">Delete</button>
               }else{
                <button type="button" class="btn btn-outline-danger" disabled>Delete</button>
                }
            </div>

Aucun commentaire:

Enregistrer un commentaire