javascript Void

javascript void is an operator for return a null value, especially useful in the hyperlinks to avoid loading new pages.

Here is a typical hyperlink:
<a href="">Home</a>
Home, If you click the link, the home page will be loaded.

We can use a hyperlink execute javascript, rather than loading a new web page:
<a href="javascript: alert('JS');">JS Link</a>
JS Link

Use void to assign value:
<a href="javascript:void(x=5);alert(x);">JS Link</a>

void(0) to avoid page loading:
<a href="javascript:void(0)"

Without void(0), page reloaded by a click:
<a href="" ondblclick="alert('dblclick')">Link</a>

void(0) provides a null value for href, thus avoids the unnecessary page loading. © 2019  Terms of Use | Home