I use jQuery, I need to make some anchor tags perform no action.
I usually write it like this:
link
H
There are so many ways to do it like
Dont add and href
attribute
<a name="here"> Test <a>
You can add onclick event instead of href like
<a name="here" onclick="YourFunction()"> Test <a>
Or you can add void function like this which would be the best way
<a href="javascript:void(0);">
<a href="javascript:;">
I encountered this issue on a WordPress site. The headers on dropdown menus always had the attribute href=""
and the header plugin being used only allowed standard urls. The easiest solution there was just to run this code in the footer:
jQuery('[href=""]').click(function(e){
e.preventDefault();
});
This will prevent blank anchors from doing anything.
React no longer support using a function like this href="javascript:void(0)"
in your anchor tag, but here is something that works pretty well.
<a href="#" onClick={() => null} >link</a>
You can do it by
<a style='cursor:pointer' >Link</a>
What do you mean by nothing?
<a href='about:blank'>blank page</a>
or
<a href='whatever' onclick='return false;'>won't navigate</a>
This answer should be updated to reflect new web standards (HTML5).
This:
<a tabindex="0">This represents a placeholder hyperlink</a>
... is valid HTML5. The tabindex attribute makes it keyboard focusable like normal hyperlinks. You might as well use the span
element for this as mentioned previously, but I find using the a
element more elegant.
See: https://w3c.github.io/html-reference/a.html
and: https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-href