Hello!

Tell me, please, how to click on the button "Add to cart" of a particular product - to take from it the same quantity of goods that the user entered?

Now, with the help of alert() quantity of goods is always the same product, regardless of which one you click on.

Here is an example - link

Update:

Why, if in <div class="price"> to attach another div <div class="price"><div class="qwerty"><input class="qty" ... and then when referring to parseInt($(this).closest('.qwerty').find('.qty').val(), 10); does not work?

Closed due to the fact that off-topic participants Vadim Ovchinnikov , Denis Bubnov , user194374, vp_arth , rjhdby 24 Feb '17 at 22:04 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Vadim Ovchinnikov, Denis Bubnov, Community Spirit, vp_arth, rjhdby
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Do not set the same id different elements:

     qty = parseInt($(this).closest('.price').find('.qty').val(), 10); 

    Well: <input class="qty" ... Same for id="mot" .

    Update:

    Because ".qwerty" not in the chain of parents ".add-to-cart" - http://api.jquery.com/closest/