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

94
Visualizações
how to check dynamically created checkbox is checked using jquery
$("input[type='checkbox']").change(function(){
  if(this.checked){
    if($(':checkbox:checked').length>1 && $('#qT').val()==1){
        $(this).prop( "checked", false );
    }
  }
});

this is the script to run And html looks like below

<div class=row>....
<div class="isCorrect">
    <span>correct</span>
    <input type="checkbox" class="form-check-input mx-1"value="1">
</div>...</div>
<div class=row>....
<div class="isCorrect">
     <span>correct</span>
     <input type="checkbox" class="form-check-input mx-1"value="1">
</div>...</div> 
etc etc

This code only checks the first check box. not any other.. I also tried

$("input[type='checkbox']").change(function(){
  if(this.checked){
    if($(':checkbox:checked').length>1 && $('#qT').val()==1){
        $(this).prop( "checked", false );
    }
  }
}).triger(change);

and many other ways

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your code is not working because your event handler is created before the dynamic checkboxes are. To bypass this, you can bind an event handler to the whole document or, for better performance, to the parent that contains all your checkboxes :

$(document).on('change',"input[type='checkbox']",function () {

    // your code here...

});
about 4 years ago · Juan Pablo Isaza Relatório

0

This should work.

When dealing with dynamic elements you have to start your selector with an element that is not dynamic and is already on the page. I like using the on method when dealing with events because it gives you more control. As you see I then define the event and then select the dynamic element that I am targeting.

Here is another reference.

$("document").on("change", "input", function(){
  if($(this).checked && $('#qT').val()==1){
     $(this).prop( "checked", false );
  }
});
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