user2856066
user2856066

Reputation: 821

Prevent row click in list when button is pressed

I am using a v-list with a click event on v-list-tile. I would also like to have a button in v-list-tile-action with a click event. My problem is that both events fires when I press the button in v-list-tile-action.

I would like to have both event, one for the row and one for the button but how can I prevent the v-list-tile / row click to fire when the button is pressed?

Upvotes: 1

Views: 3134

Answers (2)

user2856066
user2856066

Reputation: 821

Thanks for answering but I figure it out, just use @click.stop=""

Upvotes: 4

jjoselon
jjoselon

Reputation: 2811

A script of example of How prevent events propagation

$(document).ready(function(){
    $("span").click(function(event){
        event.stopPropagation();
        alert("The span element was clicked.");
    });
    $("p").click(function(event){
        alert("The p element was clicked.");
    });
    $("div").click(function(){
        alert("The div element was clicked.");
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="height:100px;width:500px;padding:10px;border:1px solid blue;background-color:lightblue;">
This is a div element.
<p style="background-color:pink">This is a p element, in the div element. <br><span style="background-color:orange">This is a span element in the p and the div element.</span></p></div>

<p><b>Note:</b> Click on each of the elements above. When clicking on the <b>div</b> element, it will alert that the div element was clicked. When clicking on the <b>p</b> element, it will return both the p and the div element, since the p element is inside the div element. 
But when clicking on the <b>span</b> element, it will only return itself, and not the p and the div element (even though its inside these elements).  The event.stopPropagation() stops the click event from bubbling to the parent elements. 
</p>

<p><b>Tip:</b> Try to remove the event.stopPropagation() line, and click on the span element again (the click event will now bubble up to parent elements).</p>

As you can see the event has a method called stopPropagation, I am using JQuery, Javascript native is the same.

Upvotes: -2

Related Questions