Forum : javascript void
Brief description  about Online courses   join in Online courses
View kaushik  n 's Profile

javascript void

what is void in javascript ? is it an operator? if it is then how is it acting??
Asked by kaushik n | Jul 29, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Kaushik,

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.

To prevent the load from refreshing, you could use the JavaScript void() function and pass a parameter of 0 (zero).
Example of void(0):

We have a link that should only do something (i.e. display a message) upon two clicks (i.e. a double click). If you click once, nothing should happen. We can specify the double click code by using JavaScript's "ondblclick" method. To prevent the page reloading upon a single click, we can use "JavaScript:void(0);" within the anchor link.

Code:(Try this)
<a href="JavaScript:void(0);" ondblclick="alert('Well done!')">Double Click Me!</a>

Try without void(0) and check. It will refresh page.
Jul 29, 2010