I have a button that's located in an anchor, and that button has some logic that's triggerd by clicking
on it.
The problem is that whenever I click on that button, the app get's redirected due the anchor
parent element.
<a href="foo" id="bar">
<span id="button">click me</span>
</a>
I tried using .stopPropagation() like it's mentioned in this post, however it doesn't work.
I tried:
$('#button').on('click', function(e) {
e.stopPropagation();
})
However, if I replace the parent anchor
with a div
, then it works - JSFiddle
Am I doing something wrong?
Update: I know I can prevent redirecting with e.preventDefault()
, however, I want when I click on the parent element to redirect, and when I click on the button not to redirect and start doing my JS functions (open modal).