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
16 May 2020 at 05:56 PM
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>
0
give a positive ratinggive a negative rating
17 May 2020 at 10:57 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us