Answers for "anchor element onclick not working"

1

anchor element onclick not working

//Onclick event of anchor tag won't work if href is set.
//Workaround: make href call a function that does onclick and then redirects page to link address
//NOT GOOD: <a href="/info" onclick="doSomething();" >Link </a>
//BETTER: <a href="javascript:onLinkClick();" >Link </a>
function onLinkClick()
{
  doSomething();
  window.location.href = "/info";
}
Posted by: Guest on August-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language