javascript:void(0)Meaning

We often usejavascript:void(0)Such code, then in JavaScriptjavascript:void(0)What does it mean?

javascript:void(0)The most critical part isvoidkeyword,voidis a very important keyword in JavaScript. This operator specifies to evaluate an expression but not return a value.

The syntax format is as follows:

void func()
javascript:void func()

or

void(func())
javascript:void(func())

The following code creates a hyperlink. Nothing will happen when the user clicks it.

Examples

<a href="javascript:void(0)">Click here and nothing will happen</a>

Try it Yourself »

When the user clicks the link, void(0) evaluates to 0, but has no effect on JavaScript.

In the following example, a warning message is displayed after the user clicks the link:

Examples

<p>Click the link below to see the result:</p> <a href="javascript:void(alert('Warning!!!'))">Click me!</a>

Try it Yourself »

In the following example, parameter a will return undefined:

Examples

function getValue(){ var a,b,c; a = void ( b = 5, c = 7 ); document.write('a = ' + a + ' b = ' + b +' c = ' + c ); }

Try it Yourself »

The difference between href="../index.html" and href="#"

#contains location information, and the default anchor is#topthat is, the top of the webpage.

And javascript:void(0) simply represents a dead link.

When the page is very long, use#to locate a specific position on the page, the format is:# + id。

If you want to define a dead link, use javascript:void(0).

Examples

<a href="javascript:void(0);">Click me, no response!</a> <a href="#pos">Click me to locate to the specified position!</a> <br> ... <br> <p id="pos">Bottom anchor point</p>

Try it Yourself »
Other Extensions