I have a cart options that has a increment the product option . The option has an text input and plus / minus options
Markup
<td class="cart-item-qty">
<div class="quantity-mius">-</div>
<div class="quantity">
<input type="text" class="cart-main-product-qty" value="1" />
</div>
<div class="quantity-plus">+</div>
</td>
there is about 5 to 6 types of input like above
And the JavaScript code:
var minus = $(".quantity-mius");
var plus = $(".quantity-plus");
var itemValue = $(".cart-main-product-qty");
$(".cart-item-qty").each(function(index) {
$(this).find(plus).on('click', function(e){
e.preventDefault();
increment();
});
$(this).find(minus).on('click', function(e){
e.preventDefault();
decrement();
});
});
function increment(){
newValue = itemValue.val();
newValue++;
itemValue.val(newValue);
};
function decrement(){
newValue = itemValue.val();
newValue--;
if(newValue < 1){
itemValue.val(0);
}else{
itemValue.val(newValue);
}
};
When i press the plus button the input value increases in all the inputs and when minus then all decreases.