Is it possible to prevent the function on the <div>
element from running when clicking the button inside the div?
When clicking the button element, the function: toggleSystemDetails
should not be triggered? Is this possible in Vue?
<div v-on:click="toggleSystemDetails($event, system.id);" class="grid-tile__list-item" v-for="(system, index) in organization.systems" :key="system.id" :class="{'in-viewport fully-in-viewport': system.inview, 'is-xsmall': system.layout === 'xsmall', 'is-small': system.layout === 'small', 'is-medium': system.layout === 'medium', 'is-large': system.layout === 'large'}">
<div class="grid-tile__list-item--overlay">
<button v-on:click="toggleTileOptionsMode($event, system.id, system.name, system.layout)">
Layout Settings
</button>
</div>
Have a look at Event Modifiers,
v-on:click.stop
will stop that click from propagating or "bubbling" up to the parent element.as mentioned on the link provided by Justin you can
.self
in the click eventSay you have a parent element and some child elements.
1.(1st case) You want the parent click to do not affect the child clicks. Just put at the parent element the
.self
modifier:See it in action here
note: if you remove the
.self
when you click a child, the parent event will fire too.2.(2nd case) You have the below code:
The problem is:
The solution to this is to put the
.stop
modifier to the icon element so the parent event will not fire.See it in action here