$(".cart").click(function () { var idstr = this.id.toString(); console.log(idstr); if (cart[idstr] != undefined) { console.log("exist"); qty = cart[idstr][0] + 1; console.log(qty); console.log(cart[idstr][0]); } else { qty = 1; price = document.getElementById("price" + idstr).innerHTML; image = document.getElementById("img" + idstr).src; aname = document.getElementById("name" + idstr).innerHTML; console.log("not"); cart[idstr] = [qty, aname, image, price]; } console.log(cart); updateCart(cart); localStorage.setItem("cart", JSON.stringify(cart)); }); function updateCart(cart) { for (var item in cart) { document.getElementById("div" + item).innerHTML = "<button id='minus" + item + "' class='btn btn-primary minus'>-</button> <span id='val" + item + "''>" + cart[item][0] + "</span> <button id='plus" + item + "' class ='btn btn-primary plus'>+</button>"; } }
PUT-YOUR-CODE-HERE
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)