Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
77
rated 0 times [  78] [ 1]  / answers: 1 / hits: 38556  / 6 Years ago, thu, may 3, 2018, 12:00:00

I've got this HTML element:



<div class=list-group>
<a href=javascript:; @click=showDetails(notification, $event) class=list-group-item v-for=notification in notifications :key=notification.id>
<h4 class=list-group-item-heading>{{ '{{ notification.title }}' }}</h4>
<p class=list-group-item-text>{{ '{{ notification.created_at|moment }}' }}</p>
</a>
</div>


And this Javascript:



return new Vue({
methods: {
showDetails: function (notification, event) {
this.notification = notification

console.info(event.target)
}
}
}


The problem is that event.target return the exact element I click. That means it can be the a element, or one of it's children (h4 or p).



How do I get the a element (the element with the @click handler), even if the user clicks on one of it's children?


More From » vue.js

 Answers
5

use event.currentTarget which points to the element that you attached the listener. It does not change as the event bubbles



https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget


[#54520] Sunday, April 29, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
michelecarissab

Total Points: 730
Total Questions: 97
Total Answers: 110

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
;