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

120
Views
event not firing after some clicks

i don't understand after certain clicks add element is not firing , it just stops, my count variables are working fine but don't know what seems to be the issue here,

 $(document).on('click','.add-role-btn',function(e){
                    console.log('working')
                    if (add_count < 3){
                        $('.role-name-container').append(
                            $('<input type="text" name="role_name" class="form-control mt-3" placeholder="Role name">')
                        )
                     }
                     add_count += 1;
                    
    
                })

            $(document).on('click','.delete-role-btn',function(e){
                console.log('working')
                let last_elem = $('.role-name-container').children().last();
                
                if ($('.role-name-container').first().not(last_elem))
                {
                    last_elem.remove()
                }
                add_count -= 1;

               
                
            })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you should only manipulate the add_count variable, if you add an element or delete it. Like this:

$(document).on("click", ".add-role-btn", function (e) {
  console.log("working");
  if (add_count < 3) {
    $(".role-name-container").append(
      $(
        '<input type="text" name="role_name" class="form-control mt-3" placeholder="Role name">'
      )
    );
    add_count += 1;
  }
});

$(document).on("click", ".delete-role-btn", function (e) {
  console.log("working");
  let last_elem = $(".role-name-container").children().last();

  if ($(".role-name-container").first().not(last_elem)) {
    last_elem.remove();
    add_count -= 1;
  }
});
about 4 years ago · Juan Pablo Isaza 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!