<a href="javascript:;">Link text</a>
- that's what I usually use
DONT USE <a>
... instead use <span class='style-like-link'>
and then use the class to style it however you want.
We can achieve that using javascript void which normally involves evaluation of an expression and returning undefined, which includes adding javascript:void(0);
on the href.
The void operator is usually used merely to obtain an undefined primitive value, usually using “void(0)” (which is equivalent to “void 0”). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value).
a {
text-decoration: initial;
}
<a href="javascript:void(0);"> This link actually does nothing when clicked</a>
one way which no one has mentioned is to point the href to an empty local file location like so
<a href='\\'>my dead link</a>
why? If you use a framework such as react or angular, the compiler will spit out some warnings which can make your log or console dirty. This technique will also prevent robots or spiders from incorrectly linking things.
The following will prevent your href from being ran
<a href="#" onclick="return false;">
If you are using jQuery, event.preventDefault() can be used
Don't make it a link (although it is prefered to do it) and style it with CSS so that it looks like a link:
p.not-a-link { text-decoration: underline; cursor: pointer }
Or even better just make it a link and let the javascript function which is used e.preventDefault()
to prevent the link.
Also add the link to the href
so that users without JS enabled will still be able to use it (as a fallback).