<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:
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:
- [fix] Java Spring Boot JPA SQLSyntaxErrorException: Encountered user at line 1 column 14 - Java
- Todays Apple Spring Loaded Event Live Updates - Apple
- [fix] MySQL cj jdbc CommunicationsException: Communications link failure - Java
- Ways to Initialize HashMap Collection in Java - Java
- How to Remove All Terminated Console tabs at once in Eclipse - Eclipse
- List all Username and User ID using Bash Command - Bash
- [Updated] macOS 13 Ventura Supported Mac Devices List - MacOS
- What is HTTP 500 Internal Server Error Code on web browsers - HowTos