Pick up product id with Jquery

Asked

Viewed 240 times

2

I have the following code html:

inserir a descrição da imagem aqui

When he clicks delete on div excluir-produto-carrinho he must get the id of the data-id-previous cart. How do I do that?

I already tried on the delete button which is the div excluir-produto-carrinho thus:

var idStorage = $(this).data('id-prod-carrinho'); 

and comes to nothing. Like he brings nothing.

1 answer

5

It’s not working because it’s not part of $(this), you have to navigate:

var idStorage = $(this)
        .closest('.prodmostra')
        .find('.imagem-prod')
        .data('id-prod-carrinho');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.