<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)
- 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
- Fix Power Automate FLOW error - InvalidTemplate Unable to process template language expressions in action - Microsoft
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations - Android
- Clone Bitbucket repo in VS Code - HowTos
- Android Installation error: INSTALL_FAILED_OLDER_SDK on Device - Android
- How to enable Do Not Disturb (DND) mode in Microsoft Teams - Teams
- Java code to check Internet Connection on Android Device Programmatically - Android
- How to hide lines in Notepad++ - NotepadPlusPlus
- Format Code in Visual Studio - VS Code [Mac/Windows/Linux] - HowTos