Javascript void(0)
Usually, when the user clicks a link on a page a new page loads, but this is not always the desired course of action. For example, when the user clicks a link on a page, you might want to update the value of a field in a form or the value of a variable. To prevent a page from reloading when a link is clicked, the void(0) function is used.
Example:
<a href="" onclick="alert('You have clicked the button')>Click here!</a>
Output:
Click on the above link. Even though the code within it specifies to display a message in an alert box (and this action does take place), the page will reload automatically.
We can fix this with void(0):
<a href="javascript:void(0);" onclick="alert('You have clicked the button')>Click here!</a>
Output:
In the above example, a message is displayed in an alert box as intended and void(0) prevents the page from reloading.