Javascript function in link href="" - prevent from redirecting

I have a javascript function in HTML link HREF="" attribute. When I click on the link, it will rediect me on another page. What should I do to avoid the redirecting.
16 May 2020 at 05:56 PM
0pnshow more

To prevent from leaving the page after you click on the link, you have to use void(0); in href attribute and add javascript function into onClick event.

The solution should look like this:

<a href="javascript: void(0);" onClick="javascript: alert('Javascript function'); ">Link</a>
17 May 2020 at 10:57 AM
0pnshow more
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2021 AnswerTabsTermsContact us