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

117
Views
jQuery on change of last element which is dynamically added

I need to run jQuery on the last element of a specific class that is dynamically generated.

Classically I would use:

    $(".class").last().on("change", function(){
       something();
    });

but since the .class element is generated through jQuery after the page is rendered, I have to use:

$("body").on("change", ".class", function(){
  something();
});

but this entry causes the change in the first (or any) element on the page to trigger the event.

I would need to somehow include the .last() function into the second selector.

Simply: I have an input on the page that is empty, when a change is made to it, a copy of this input with empty content should be generated and inserted after the first input. If this one is filled, another one is generated. Currently (using $("body").on("change",...) the next input is generated again and again even if I change the first input field X times.

Thanks everyone

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

0

You can ask

$("body").on("change", ".class", function(){
  if($(this).is(':last-child')) {
    //something
  }
});
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!