Currently, I am working on developing a shopping cart website and I am new to using Jquery. My layout involves the need to increment and decrement values by one when the plus and minus button is pressed. Additionally, the total price value should also be adjusted accordingly. Below is the Jquery code I have attempted:
//Add and Subtract
$("#add").on('click',function()
{
if(parseInt($("#total input").val())>=0)
$("#total input").val(parseInt($("#total input").val())+1);
});
$("#sub").on('click',function()
{
if(parseInt($("input").val())>0)
$("#total input").val(parseInt($("#total input").val())-1);
});
Here is my HTML code:
<div class="btn_group" id="total">
<a href="#" class="btn_add_subtract" id="add">
+
</a>
<input type="text" class="quantity_value" value="0"/>
<a href="#" class="btn_add_subtract" id="sub">
-
</a>
</div>
However, I am facing an issue where all the data in the list is being changed when I try to increment or decrement the value. Can anyone suggest a better approach for me to achieve this functionality?
Thank you