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

100
Visualizações
stop/disable button after x amount of clicks

I have a table and you add rows using append. How do I stop or disable the button after 5 clicks or 5 append rows or any amount needed?

this is the code:

<input class="btn btn-primary" type="button" id="addbutton" value="More names" 
title="Add more names">

<script type="text/javascript">
  var i = 1; 
$("#addbutton").click(function () {
    $("#table").append('<tr>'+
     '<td><input class="form-control input-lg" type="text" name="name" required />'+ 
'</td>'+
    '<td><button type="button" class="removebutton" title="Remove this row">X</button> 
</td></tr>').find("input").each(function () {
});
i++;
});;

$(document).on('click', 'button.removebutton', function () {
    $(this).closest('tr').remove();
    return false;
});
</script>
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You want to disable the button so there is an attribute in HTML, we can use that. The thing is, you should keep the value of i == 0 instead of 1.

if(i == 5){
$("#addbutton").attr('disabled','disabled');
}

This is how you can add a disabled attribute. Hope this would help you.

about 4 years ago · Santiago Trujillo 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