I’m trying to prevent the default anchor link and onclick event to trigger.
Here’s the HTML code:
<a id="mylink" href="http://google.com"
onclick="window.location.href='http://google.com.au'; return false;">
Google</a>
I’m trying to prevent any redirects from occurring, using the following jQuery code:
$("#mylink").click(function(ev) {
ev.preventDefault();
ev.stopPropagation();
}
But it doesn’t seem to work. The code still invokes the anchor onclick event and redirects to http://google.com.au
Any clues or suggestions? Thanks in advance.
You need to clear
onclickmanually, as long as it is being called before.click()callback: