@click.capture is not working for me. #12794
-
Dear all, I have a relatively simple code and I would like to have the event trigger only on the parent (or the element I actually put the @click on): <template>
<button @click.capture.stop="callFunction">
<div id="child"></div>
</button>
</template>
<script setup>
function callFunction (event) {
console.log(event.target) // This will always be the child div.
}
<script> Is this normal, am I missing something or is the capture buggy? (checked in latest chrome and firefox) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The code is working as expected, by What you want is
https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget |
Beta Was this translation helpful? Give feedback.
The code is working as expected, by
event.target
gives you the element that caused the event, which is the div, as that was what you clicked on.What you want is
event.currentTarget
, which is the element that the event handler was attached to.https://developer.mozilla.org/en-US/docs/W…