javascript:void(0) Meaning
We often use code like javascript:void(0), so in JavaScript javascript:void(0) represents What does that mean?
The most critical thing in javascript:void(0) is the void keyword. void is a very important keyword in JavaScript. This operator specifies to calculate an expression but does not return a value.
The syntax format is as follows:
<head> <script type="text/javascript"> <!-- void func() javascript:void func() 或者 void(func()) javascript:void(func()) //--> </script> </head>
The following code creates a hyperlink, and nothing will happen when the user clicks it.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <a href="javascript:void(0)">单此处什么也不会发生</a> </body> </html>
When the user links, 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:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript"> <!-- //--> </script> </head> <body> <p>点击以下链接查看结果:</p> <a href="javascript:void(alert('Warning!!!'))">点我!</a> </body> </html>
The difference between href="#" and href="javascript:void(0)"
# contains a location information. The default anchor is #top, which is the top of the web page.
And javascript:void(0) only represents a dead link.
When the page is very long, # will be used to locate the specific location of the page. The format is: # + id.
If you want to define a dead link, please use javascript:void(0).