Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda