Is this right? Or is there some obscure bug/use case I need to be aware of?
A label simply provides an identifier to a statement, and lets you refer to it elsewhere in your program.
IMHO, this pseudo-protocol is only useful for bookmarklets…
As other answers have mentioned, avoid the use of
A tags are sometimes still semantically correct, you will need to put something in the
href attribute if you want your
:hover CSS styles to be applied to the element in Internet Explorer. In this case, use:
<a href="#" onclick="doSomething(); return false;">Link</a>
* I probably should have specified the version when I first wrote this. I don’t remember at all, but just in case the bug is present only in a now-mostly-defunct browser like IE 6 or 7, you are probably best to test it yourself.
Don’t specify it at all, ever. It’s wrong to do it in
<a> tags, which instead should be coded like this:
<a href="#" onclick='alert("Hello")'>World</a>
It’s a remnant from days gone by. The only time I can think of where it’s used would be in the browser address bar (and bookmarklet bookmarks). Keep it out of your pages.
In practice, you are correct.
You need to do this in any instance where something other than script is expected. In theory, you can stick
However, you really shouldn’t use
You should all check out
Especially the post by “Lasse Reichstein Nielsen”,because most answers are here are incorrect in some fashion.
Also remember that the anchor tag does not require a href at all! That is
<a>hi</a> is valid xhtml. The problem using
href="#" is that it may scroll to the top of the page.. it is simply not needed. Lastly if you do not actually want the behavior of the anchor tag you should not use it. You can simulate an anchor using css (
cursor:pointer) and events like mouseenter and mouseleave (which is more work, but does not “break” the expected behavior of an anchor tag).