Why not fire the onclick event?

Trying to associate two counters so that they move simultaneously. The problem is that when adding to the cart and pressed her on the "plus" or "minus" counters don't change, ie event does not occur, although the HTML is the same as those in the catalog. When you add row "$(`.counterPlus`).on("click", plus)" and "$(`.counterMinus`).on("click", minus)" inside the function adds items to the cart event begins to be captured, but then it starts to work twice/three times/four times/... (depending on how many times the "add to cart" has been called). CANT?

HTML: https://pastebin.com/vwgMAajA
CSS: https://pastebin.com/bRTvcQcA
JS: https://pastebin.com/evjM5Fm9
5e401e8515aa5460085490.png
April 7th 20 at 10:50
1 answer
April 7th 20 at 10:52
Solution
Try this:
$('body').on("click", '.counterPlus', plus)
Yes, thank you, it worked. - Tyree_Zieme commented on April 7th 20 at 10:55
@Tyree_Zieme, But it is better to hang up the handler on body but not on the item close to your buttons. The closer the better for performance - Brandt_Ritchie commented on April 7th 20 at 10:58

Find more questions by tags JavaScript