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.
0
give a positive ratinggive a negative rating
Hi,

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>
Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us