Nick Vlasov Nick Vlasov -4 years ago 83
HTML Question

jQuery increase value only at clicked div

I need to increase value, by clicking plus or minus picture. It works fine when it's only one "item_quantity" block at the page. But it works incorrectly if I wanna add another "item_quantity" block.

JS code that increase value:

$('.item_quantity .plus').click(function() {
var num = parseInt($('.item_quantity .quan_numb').text());
$('.item_quantity .quan_numb').text(num + 1);
});


http://codepen.io/Vlasov/pen/dvogmp?editors=1010

Answer Source
$(this).parent().find('.quan_numb')

http://codepen.io/anon/pen/ZeGqmd?editors=1010

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download