This question has already been answered:

$(".cartProduct").each(function() { var priceOfProduct = $(this).children(".priceOfProduct").text(); var numberOfProductCart=1; $(this).children(".sumPriceOfProduct").text(numberOfProductCart*priceOfProduct); $(this).find('.shest').keyup(function() { numberOfProductCart = $(this).val(); $(".sumPriceOfProduct").text(numberOfProductCart*priceOfProduct); }); }); 

The sumPriceOfProduct class is a child of cartProduct , which has an infinite number of pieces. It is necessary that sumPriceOfProduct in each cartProduct independently, I thought this would help here, but with this it calls the anonymous function at the keyup event, but it is necessary for the cartProduct to cartProduct .

Reported as a duplicate by Grundy , aleksandr barakin , user194374, Denis , user207618 members on Aug 14 '16 at 12:13 pm .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    A callback that is passed to each is called with 2 parameters - a key (number) and a value. You can use them or save this in some variable - for example self

      $(".cartProduct").each(function(i, el) { var self = this; var priceOfProduct = $(el).children(".priceOfProduct").text(); var numberOfProductCart=1; $(el).children(".sumPriceOfProduct").text(numberOfProductCart*priceOfProduct); $(el).find('.shest').keyup(function() { numberOfProductCart = $(this).val(); $(el).children(".sumPriceOfProduct").text(numberOfProductCart*priceOfProduct); }); }); 
    • Now it gives out zero, but I have to give out the amount of goods multiplied by its price, before that and that, I just needed an event that multiplies them. - Qop Op
    • Yes, and here in the version that I laid out everything happens correctly, but for all sumPriceOfProduct immediately. - Qop Op
    • @QopOp Corrected - Mihanik71