Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!