I have counters in my cart and I'm struggling to get the controls to only target the specific counter I'm on. Instead, it's updating them all.
// Product Counter
DecreaseCount = function(){
var count = $(".quantity__count").val();
if (count > 0) count--;
if (count == 0) count = 0;
$(".quantity__count").val(count);
}
IncreaseCount = function(){
var count = $('.quantity__count').val();
if (count < 99) count++;
if (count == 99) count = 99;
$('.quantity__count').val(count);
}
// Does both
$('.quantity__decrement').click(function(){
DecreaseCount();
});
$('.quantity__increment').click(function(){
IncreaseCount();
});
// What I've tried
//$('.quantity__decrement').each(function(){
// $(this).on("click", function(){
// debugger;
// var count = $(".quantity__count").val();
// if (count > 0) count--;
// if (count == 0) count = 0;
// $(".quantity__count").val(count);
// });
//});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="o-grid o-grid--no-gutter">
<div class="quantity o-grid__cell">
<div class="quantity__decrement">-</div>
<input type="num" class="quantity__count" value="0" />
<div class="quantity__increment">+</div>
</div>
</div>
<div class="o-grid o-grid--no-gutter">
<div class="quantity o-grid__cell">
<div class="quantity__decrement">-</div>
<input type="num" class="quantity__count" value="0" />
<div class="quantity__increment">+</div>
</div>
</div>
I've tried using .closest, .siblings etc; I'm a bit stumped and I know this isn't a tricky thing to do.
Any help is appreciated!