Cancel spouting on HTML anchor tag
I have the following setting on my web page.
<div id="clickable">
<a href="hello.com">Here!</a>
</div>
Is there a way I could use to avoid the click event to trigger the div. I suppose this is due to setting something in the attribute onclickfor the anchor tag, but trying simple things like this e.preventDefault()did not work.
Help? Thank!
+5
4 answers
e.preventDefault (); do not work in onclick attributes because e is not defined. Also e.preventDefault (); don't want you to stop bubbling, you need e.stopPropagation ();
Use either
onclick="$(this).stopPropagation();"
anchored or
$(a).click(function(e){
e.stopPropagation();
});
in your events.
+6
user910533
source
share