I want a link that does nothing. I don't want this:
<a href="#">
because then the URL becomes something.com/whatever/#
.
The only reason I want a link is so the user can see that they can click on the text. JavaScript is being used to perform some action so I don't need the link to go anywhere but I need it to look like a link!
I could use some data attribute and tell me CSS to make elements look like links if they have this attribute but it seems a bit overkill.
To make an anchor tag refer to nothing, use “javascript: void(0)”. The following link does nothing because the expression "0" has no effect in JavaScript. Here the expression "0" is evaluated, but it is not loaded back into the current document.
The Short Answer: href="#0" I like this because: It doesn't navigate. It makes it obvious that this it's a do-nothing navigation.
To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a href=” ”>.
The following will prevent your href from being ran
<a href="#" onclick="return false;">
If you are using jQuery, event.preventDefault()
can be used
Try this:
<a href="javascript:void(0);">link</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With