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

172
Visualizações
one button to check all check boxes and un check them too

I have 3 check box and one button so when I click in this button all must checked and if i click again all must uncheck but it does not working I want all function inside my object like this

btn: null,
  check: function(checked = true) {
    const checkboxes = document.querySelectorAll('input[name="cb"]');
    checkboxes.forEach((checkbox) => {
      checkbox.checked = checked;
    });

  },
  checkAll: function() {
    this.check();
    this.onclick = uncheckAll;
  },

  uncheckAll: function() {
    this.check(false);
    this.onclick = checkAll;
  },
}

btn.check();
<body style="background-color: #0d1117; color: #6D859E">
  <div style="margin: 60px;">
    <button id="btn">Check / Uncheck All</button>

    <ul style="list-style-type: none; padding: 0">
      <li>
        <label for="c1"><input type="checkbox" name="cb" value="1" id="c1">1</label>
      </li>
      <li>
        <label for="c2"><input type="checkbox" name="cb" value="2" id="c2">2</label>
      </li>
      <li>
        <label for="c3"> <input type="checkbox" name="cb" value="3" id="c3">3</label>
      </li>
    </ul>
  </div>
</body>

about 4 years ago · Juan Pablo Isaza
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