Estoy tratando de obtener la cantidad de máquinas que seleccioné.
aquí tenemos una lista de máquinas virtuales y me gustaría contar la selección que es cuando presiono una entrada allí está el elemento que está marcado.
Intenté esto pero no funcionó.
$("table input[type=checkbox]").click(function(){ let nbchecked = $("table input[type='checkbox']:checked").length; console.log(nbchecked); let len = nbchecked.length; $(".counter").html(nbchecked); //inject the number of vm checked in the div });Soy principiante en javascript y jquery y no se como hacerlo. necesito tu ayuda por favor
Funciona, publique su html por favor
$("table input[type=checkbox]").click(function(){ let nbchecked = $("table input[type='checkbox']:checked").length; console.log(nbchecked); let len = nbchecked.length; $(".counter").html(nbchecked); //inject the number of vm checked in the div }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table class="table" id="vm_table"> <tbody> <tr> <td> <label for="id_vms_1"> <input type="checkbox" name="vms" value="12" id="id_vms_1"> vm1 </label> </td> </tr> <tr> <td> <label for="id_vms_2"> <input type="checkbox" name="vms" value="13" id="id_vms_2"> vm2 </label> </td> </tr> <tr> <td> <label for="id_vms_3"> <input type="checkbox" name="vms" value="14" id="id_vms_3"> vm3 </label> </td> </tr> </tbody> </table> <div class="counter"></div>