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

120
Visualizações
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 Respostas
Responde à pergunta

0

You can ask

$("body").on("change", ".class", function(){
  if($(this).is(':last-child')) {
    //something
  }
});
about 4 years ago · Juan Pablo Isaza 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