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

105
Visualizações
jQuery event handler not working on form elements that are dynamically inserted

I three + and - buttons on Shopify that looks like (below). The problem is Shopify doesn't include 3 different forms, it dynamically updates the HTML attributes to show the other buttons. So when I click the second + button it increments by 2 instead of 1. Only the first one works.

The first + button works and increments or decrements by 1. But the second increments by 2. And the third doesn't work at all.

How to make click event apply to elements that are dynamically updated in the HTML?

jQuery

$('.plus').on('click', function(e) {
  var val = parseInt($(this).prev('input').val());
  $(this).prev('input').val(val + 1);
});
$('.minus').on('click', function(e) {
  var val = parseInt($(this).next('input').val());
  if (val !== 0) {
    $(this).next('input').val(val - 1);
  }
  if (val == 0) {
    $(this).next('input').val(1);
  }
});

HTML:

<div class="product-form__item product-form__item--quantity quantitiy_dv">
    <label class="quantitiy" for="Quantity-collection-template-new"></label>
    <input class="minus minus1" type="button" value="-">
    <input type="number" id="Quantity-collection-template-new" name="quantity" value="1" min="1" class="product-form__input qty" pattern="[0-9]*" data-quantity-input="">
    <input class="plus plus1" type="button" value="+">
</div>

Please let me know if you need more information!

about 4 years ago · Juan Pablo Isaza
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