I have a span tag inside an anchor tag. When span is clicked I want the link to not get followed, that is I want to stop the click on span to trigger(bubble up) click on anchor tag. For that I used stopPropagation as:
$("a span").click(function(e){
e.stopPropagation();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="http://stackoverflow.com">
hello <span> click here </span>
</a>
As you can see the click event is still propagated to anchor tag. Instead, if I use e.preventDefault()
then that seems to stop the bubbling up. Why isn't the stopPropagation
stopping the propagation of click event?