Greetings Independently decided to develop a basket script on jquery.
I managed to sum up the quantity of goods and their total prices, but I can’t understand how to subtract the total amount by pressing a certain button - that is, subtract the cost of the last added product from the total amount.
Below is the code:
$(document).ready(function(){ //add price and quantity in shoping cart $(".item_shop").on("click",".in_cart", function() { var price = +$(this).closest(".item_shop").data("price"); $("#summ").text(function(i, val) { return val * 1 + price; }); $("#items").text(function(i, val) { return val * 1 + 1; }); }); //remove items and quantity in shopnig cart $(".right").on("click", function(event) { event.preventDefault(); var price = +$(this).closest(".item_shop").data("price"); $("#summ").prev().val($("#summ").text()); // в данной строке все никак не могу придумать, что прописать чтобы уменьшалась сумма последнего добавленного товара. $("#items").text(function(i, val) { return val * 1 - 1; // здесь количество минусует, но также уходит в минус, что конечно не желательно. }); }); });// end of function Thank you in advance.