E
E
Eugene2019-12-08 19:12:50
Vue.js
Eugene, 2019-12-08 19:12:50

How to get information about the parent block when clicking on the child?

I have a product card on which the v-on:click="heandler($event)" handler is hung. In the handler, the target and id of the card on which the click was made are pulled out from the event object. But when a child element is clicked, a nested element that does not have an id gets into target, and I cannot determine which card was clicked on. Is there a way to pass the parent element to the event?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-12-08
@you_are_enot

Instead of target , use currentTarget .
But it's not clear at all - what prevents you from immediately passing the id of the card (or the entire object) to the click handler?

S
Sergey delphinpro, 2019-12-08
@delphinpro

Use the .self modifier
Then event.target will contain the element on which you hung the handler

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question