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

103
Views
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
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!