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.