Home > Web Front-end > Front-end Q&A > What is the reason for using javascript:void(0)

What is the reason for using javascript:void(0)

WBOY
Release: 2022-04-13 17:48:10
Original
3322 people have browsed it

The reason for using "javascript:void(0)" is to prevent the link from jumping to other pages, retain the link's style, and prevent the link from performing actual operations. The void keyword is used to specify that an expression is to be evaluated but no value is returned. "void(0)" means no operation is performed.

What is the reason for using javascript:void(0)

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What is the reason for using javascript:void(0)

href="javascript:void(0);" The meaning of this is to let the hyperlink execute a js function instead of To jump to an address,

and void(0) represents an empty method, that is, the js function is not executed.

Why use href="javascript:void(0);"

javascript: is a pseudo-protocol, indicating that the content of the url is executed through javascript. void(0) means no operation is performed, which will prevent the link from jumping to other pages. This is often done to retain the style of the link, but does not allow the link to perform actual operations. The most critical thing in

javascript:void(0) is the void keyword, which is a very important keyword in JavaScript. Operator specifies that an expression is evaluated but does not return a value.

The syntax format is as follows:

void func()javascript:void func()
Copy after login

or

void(func())javascript:void(func())
Copy after login

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

Example:

<html>
<head> 
<meta charset="utf-8"> 
<title>123</title> 
</head> 
<body>
    <a href="javascript:void(0)">单击此处什么也不会发生</a>
</body>
</html>
Copy after login

Output result:

What is the reason for using javascript:void(0)

##[Related recommendations:

javascript video tutorial, web front end

The above is the detailed content of What is the reason for using javascript:void(0). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template