Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
selecting multiple checkboxes in separate divs with JQuery

I have several checkboxes spread across multiple divs.In all separate div I have a 'select all' checkbox. When that checkbox is selected, I am trying to get all the other ones to be selected related to that pertucular div, and when you deselect the 'select all' one, it deselects the others.

<div class="actions" id="actions" title="Actions">
   <div>
       <div><input type="checkbox" name="action" id="" class="" value="0" /> Select All</div><br />
       <div><input type="checkbox" name="action" id="" class="" value="1" /> <?php echo $lang["actions"][1]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="2" /> <?php echo $lang["actions"][2]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="3" /> <?php echo $lang["actions"][3]; ?></div><br />

   </div>
   <div>
       <div><input type="checkbox" name="action" id="" class="" value="26" />Select All</div><br />
       <div><input type="checkbox" name="action" id="" class="" value="27" /> <?php echo $lang["actions"][27]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="28" /> <?php echo $lang["actions"][28]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="29" /> <?php echo $lang["actions"][29]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="30" /> <?php echo $lang["actions"][30]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="31" /> <?php echo $lang["actions"][31]; ?></div>
   </div>
</div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here is an example

Next time show us at least a minimum of code so that we can help you understand

$('.selectAll').on('click',function(){
  let isSelected = $(this).is(':checked');
  $(this).parents('.myDiv').find('input[type="checkbox"]').each(function(){
    if( isSelected )
      $(this).prop('checked',true);
    else
      $(this).prop('checked',false);
  })
})


$('input:not(".selectAll")').on('click',function(){
  let selectAllChecked =  $(this).parents('.myDiv').find('.selectAll')[0].checked;
  let numberInput = $(this).parents('.myDiv').find('input').not('.selectAll').length;
  let numberInputChecked = $(this).parents('.myDiv').find('input:checked').not('.selectAll').length;
  
  if( selectAllChecked )
    $(this).parents('.myDiv').find('.selectAll')[0].checked = false;
      
  if( numberInput == numberInputChecked)
    $(this).parents('.myDiv').find('.selectAll')[0].checked = true;
  
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="actions" id="actions" title="Actions">
   <div class="myDiv">
       <div><input type="checkbox" name="action" id="" class="selectAll" value="0" /> Select All</div><br />
       <div><input type="checkbox" name="action" id="" class="" value="1" /> <?php echo $lang["actions"][1]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="2" /> <?php echo $lang["actions"][2]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="3" /> <?php echo $lang["actions"][3]; ?></div><br />

   </div>
   <div class="myDiv">
       <div><input type="checkbox" name="action" id="" class="selectAll" value="26" />Select All</div><br />
       <div><input type="checkbox" name="action" id="" class="" value="27" /> <?php echo $lang["actions"][27]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="28" /> <?php echo $lang["actions"][28]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="29" /> <?php echo $lang["actions"][29]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="30" /> <?php echo $lang["actions"][30]; ?></div><br />
       <div><input type="checkbox" name="action" id="" class="" value="31" /> <?php echo $lang["actions"][31]; ?></div>
   </div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda