Sometimes, you may need to call some JavaSript from within a link. Normally, when you click a link, the browser loads a new page (or refreshes the same page).
This might not always be desirable. For example, you might only want to dynamically update a form field when the user clicks a link.
void() function and pass a parameter of 0 (zero).
Example of void(0):
ondblclick method. To prevent the page reloading upon a single click, we can use
Same Example, but without void(0):
Did you notice the page refreshed as soon you clicked the link (actually, it refreshed the iframe content on this example — therefore, the above link probably disappeared when you clicked it). Even if you double clicked and triggered the
ondbclick event, it will still happen!
void(0) method can become useful when you need to call another function that may have otherwise resulted in an unwanted page refresh.
- Escape Characters