I make a basket for an online store, when you click on a button to open a basket, an ajax request is executed and div containers are displayed (for each product), each container has, for example, a button for deleting goods from the basket, which has a certain css class on which the handler is hung, which takes the id of this button, cuts the beginning, for example "tovarDelete_", and then when generating blocks of these goods, the item number was entered, directly in the css attribute id. After working with this line, the received id with the appropriate command is sent to the server. As I understand it is a terrible way to work. Tell me how these things are done correctly! Maybe when you open the basket, you need to create an object for each item, but then how to write a reference to the same item to the same item to delete it?

$('#conteyner_div').on('click', '.vkorzinu', function(){ var id = $(this).attr('id'); id = id.substr(14, id.length); inBasket(id); }); 

Here, for example, receiving id goods.

  • I just wanted to say that the basket is not the basket, that basket is the cart - Stranger in the Q
  • @StrangerintheQ I certainly don’t argue, but if I'm not mistaken, the cart is transferred to the cart, but the basket is just that basket ... - MaximLensky
  • @StrangerintheQ here is the translation from bing.com: dropbox.com/s/qlkhbh2vtycxpxf/2019-01-27_122312.png - MaximLensky
  • @PaulVarshavsky en.wikipedia.org/wiki/Shopping_cart - Stranger in the Q
  • @StrangerintheQ I understand en I don’t need a wiki - MaximLensky 3:14 pm

1 answer 1

The use of data attributes has helped.

  • 2
    Please try to leave a little more detailed answers. You can add an answer by clicking edit - aleksandr barakin