i want to change 'add cart' button to 'plus' ,'value', and 'minus' when click on "add cart" in shopping cart

 $(".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>";
    }
  }

Sorry but it’s very hard to read your code, you should add comments and white
space so that its easier to understand. I can help after that.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.