<a href="javascript:void(0)" class="something" id="action">Check</a>
When you click on a hyperlink it results in an action where the page is redirected to the location that's defined in href attribute.
If you want to display a hyperlink and but do not want to redirect to another link and yet want to perform such action you can make use of javascript:void(0) inside the href attribute.
javascript:: is the way you can perform a javaScript action.
void(0): will result in undefined and no action will be performed.
Let's see an example:
HTML:
<a href="javascript:void(0)" onClick="displayMessage()" id="link">
Click to display Message</a>
<div id="message"></div>
javaScript:
function displayMessage() {
document.getElementById("message").innerHTML = "Hello there!";
}
JSFiddle: https://jsfiddle.net/code2care/4qmbd0vs/5/
Output:
![javascript:void(0) example javascript:void(0) example](https://code2care.org/javascript/javascript-void-0-meaning-with-example/images/javascript:void(0) example.png)
javascript:void(0) example
More Posts related to JavaScript,
- How to Run JavaScript on Mac Terminal
- Get Current time in GMT/UTC using JavaScript
- How to yarn reinstall all Packages
- [javaScript] Convert text case to lowercase
- Get Device Screen Width and Height using javaScript
- Fix - npm start: sh: index.js: command not found
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- JavaScript: Convert an Image into Base64 String
- JavaScript : Get current page address
- How to get query string in JavaScript HTML location.search
- Create React App using npm command with TypeScript
- JavaScript: Count Words in a String
- Add Animated Scrolling to Html Page Title Script
- How to send email from JavaScript HTML using mailto
- Javascript convert text case from uppercase to lowercase
- Submit html form on dropdown menu value selection or change using javascript
- Send Extra Data with Ajax Get or Post Request
- Fix: SyntaxError: The requested module does not provide an export named default
- Examples: Convert String to int in JavaScript
- 10 ways to Convert String to a Number in JavaScript
- Excel Fix: SECURITY RISK Microsoft has blocked macros from running because the source of this file is untrusted.
- Fix: ReferenceError: require is not defined in ES module scope [Node]
- [JavaScript] Remove all Newlines From String
- How to detect Browser and Operating System Name and Version using JavaScript
More Posts:
- Read a File Line By Line using Java 8 Stream API - Java
- How To Remove Only Conditional Formatting in Excel - Microsoft
- How to extract numbers as list from Python String - Python
- Java 8: Convert Iterator to Stream Examples - Java
- Fix [Fatal Error] :2:6: The processing instruction target matching [xX][mM][lL] is not allowed. - Java
- Terminal display next month Calendar - Linux
- Android Studio Error: Default Activity not found - Android-Studio
- Multiple Microsoft 365 Services Down (Outlook, Teams, SharePoint, OneDrive) - 25 January 2023 (Solved) - Microsoft