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

160
Visualizações
Check only non-disabled

I have a sequence of checkboxes that can be disabled or not through the disabled in the input tag

By clicking on the parent checkbox, I need only those NOT disabled to be checked

Current and desired:

enter image description here enter image description here

Code so far:

$("#checkAll").click(function () {
   $("input:checkbox").not(this).prop("checked", this.checked);
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could use the :not() selector combined with the has attribute selector :

$("#checkAll").change(function () {
   $("input:checkbox:not([disabled])").prop("checked", this.checked);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="checkAll" />
<input type="checkbox" />
<input type="checkbox" disabled />
<input type="checkbox" />
<input type="checkbox" disabled />
<input type="checkbox" />

As suggested by @connexo, you should use .change() instead of .click(). See this answer for more information.

about 4 years ago · Juan Pablo Isaza Relatório

0

Vanilla JS, always preferred:

document.getElementById('checkAll').addEventListener('change', function() {
  for (const cb of document.querySelectorAll('input[type=checkbox]:not([disabled])')) {
    if (cb !== this) cb.checked = this.checked;
  }
});
<input type="checkbox" id="checkAll" />
<input type="checkbox" />
<input type="checkbox" disabled />
<input type="checkbox" />
<input type="checkbox" disabled />
<input type="checkbox" />

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