How to execute onClick and href both in an anchor tag (<a>)

anchor, html, javascript, onclick

Solution

I think the easiest way to do it is to make your function return true, so that after the function is complete, the anchor tag will behave like it normally does. This way you can also use the target-attribute if you want to use new window:

function myFunction() {
  alert("hello");
  return true;
}
<a href='http://www.google.com' onclick="myFunction();" target="google">Click me</a>

Problem

I have a link as follows: ``` <a href="www.google.com" onClick="someFunction()">Click me</a> ``` On clicking the link, it's executing the JavaScript function, but it is not taking me to the href link. How can I achieve the same?

Original source

Related problems