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.
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
Try it Yourself »
In the following example, parameter a will return undefined:
Examples
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
Try it Yourself »