I'm trying to get the id of a div element that I show from the database. The ID is generated dynamically, and it corresponds whit the record id, but when I try to get the id through a click event, I get only the id of the first element, or in other cases, all the ID's of the dynamic fields.
Here is the code fragment of my .js file:
/* Every field element is dynamically generated */
$('#data .fields[id^=field_]').click(async() => {
$('form').attr("action", "http://xx.xx.7.205:3000/api/pedidos/modificar");
const id = $(this).attr('id').slice('-')[1];
const ret = new Buscar();
const json = ret.buscar(id);
llenarCamposFormulario(id, json);
$('.anular').click(async() => {
const ret2 = new eliminarPedido();
const what = await ret2.buscar(id);
console.log(what);
resetFields();
});
});
Thanks in advance!