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

253
Visualizações
How to unchecked child checkbox on click parent checkbox

Hello I need to check and uncheck child checkboxes on click parent checkboxes, Right now I'm able to check child checkboxes but not able to uncheck those by click on the same, how to achieve this.

my code

HTML

 <ul class="theme-list-p">
                          <li>
                            <input type="checkbox" name="">&nbsp;&nbsp;Ambah
                            <ul class="theme-list-c">
                              <li><input type="checkbox" name="">&nbsp;&nbsp;Kirnapur</li>
                              <li><input type="checkbox" name="">&nbsp;&nbsp;Barwani</li>
                              <li><input type="checkbox" name="">&nbsp;&nbsp;Sihora</li>
                            </ul>
                          </li>
                          <li><input type="checkbox" name="">&nbsp;&nbsp;Sabalgarh
                            <ul class="theme-list-c">
                              <li><input type="checkbox" name="">&nbsp;&nbsp;Village1</li>
                              <li><input type="checkbox" name="">&nbsp;&nbsp;Village2</li>
                              <li><input type="checkbox" name="">&nbsp;&nbsp;Village3</li>
                            </ul>
                          </li>
                          <li><input type="checkbox" name="">&nbsp;&nbsp;Kailaras</li>
                        </ul>

CSS

.theme-list-p{

  list-style: none;
  padding-left: 10px;
  font-weight: bold;
  border:1px solid #dee2e6;
  padding: 5px;
  overflow-y: scroll;
  min-height: 120px;
}

.theme-list-c{
  list-style: none;
  padding-left: 20px;
  font-weight: 400;
}

jquery

<script type="text/javascript">
  $(document).on('change', '.theme-list-p li', function(){
     $(this).find('.theme-list-c li input').attr('checked', true);
  });
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could do it like this:

$(document).on('change', '.theme-list-p li input', function() {
  $(this).next('.theme-list-c').find('li input').attr('checked', $(this).is(":checked"));
});

Demo

$(document).on('change', '.theme-list-p li input', function() {
  $(this).next('.theme-list-c').find('li input').attr('checked', $(this).is(":checked"));
});
.theme-list-p {
  list-style: none;
  padding-left: 10px;
  font-weight: bold;
  border: 1px solid #dee2e6;
  padding: 5px;
  overflow-y: scroll;
  min-height: 120px;
}

.theme-list-c {
  list-style: none;
  padding-left: 20px;
  font-weight: 400;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="theme-list-p">
  <li>
    <input type="checkbox" name="">&nbsp;&nbsp;Ambah
    <ul class="theme-list-c">
      <li><input type="checkbox" name="">&nbsp;&nbsp;Kirnapur</li>
      <li><input type="checkbox" name="">&nbsp;&nbsp;Barwani</li>
      <li><input type="checkbox" name="">&nbsp;&nbsp;Sihora</li>
    </ul>
  </li>
  <li><input type="checkbox" name="">&nbsp;&nbsp;Sabalgarh
    <ul class="theme-list-c">
      <li><input type="checkbox" name="">&nbsp;&nbsp;Village1</li>
      <li><input type="checkbox" name="">&nbsp;&nbsp;Village2</li>
      <li><input type="checkbox" name="">&nbsp;&nbsp;Village3</li>
    </ul>
  </li>
  <li><input type="checkbox" name="">&nbsp;&nbsp;Kailaras</li>
</ul>

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