<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:
 example.png)
javascript:void(0) example
More Posts related to JavaScript,
- How to get UTC (GMT) time using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- How to detect Browser and Operating System Name and Version using JavaScript
- JavaScript : Get current page address
- [javaScript] Convert text case to lowercase
- How to check if a String contains substring or a word using javaScript
- Writing your first Hello, World! 🌍 JavaScript code Tutorial
- JavaScript: Check if variable is a number
- How to send email from JavaScript HTML using mailto
- Meaning of javascript:void(0) explained with example
- How to get query string in JavaScript HTML location.search
- Javascript convert text case from uppercase to lowercase
- Loading previous page using html button using JavaScript
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- How to get current URL Location using Javascript HTML
- Detect if Cookies are enabled using JavaScript
- Write javaScript code in Swedish using FikaScript
- Add Animated Scrolling to Html Page Title Script
- JavaScript: Convert an Image into Base64 String
- Remove items from JavaScript array
- Send Extra Data with Ajax Get or Post Request
- How to Print from JavaScript HTML using window.print
- Get Device Screen Width and Height using javaScript
- Examples: Convert String to int in JavaScript
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json
More Posts:
- AlertDialog with single button example : Android - Android
- Resolving DNS_PROBE_FINISHED_NXDOMAIN Google Chrome Error - Google
- How to Copy files from Docker Container to Host System - Docker
- Upload docx file using PHP script - PHP
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory - Bash
- How to uninstall pip Python packages - Python
- How to install AWS CLI on Ubuntu - AWS
- Java 8 - Convert List to Map Examples - Java