I’ve encountered hrefs like this before, but I’m not sure what they signify.
Asked by omg
The following is an explanation of the void operator:
Answered by rahul
a href=”#”> is a popular alternative that could be considered less awful. To prevent the link from being followed and scrolling to the top of the page, remember to return false from your onclick event handler.
Otherwise, a link that just points to a script isn’t actually a link and shouldn’t be marked up as one. Adding the onclick to a span>, div>, or a> without a href and styling it in some way to make it apparent you can click on it is the standard approach. StackOverflow used to do this [at the time of writing; currently it uses href=”#”].
The negative is that you lose keyboard control because you can’t tab or activate a span/div/bare-a with space. Whether or not this is a drawback depends on the type of operation the element is supposed to do. By adding a tabIndex to the element and listening for a Space keypress, you may try to imitate keyboard interactability with some effort. However, it will never be able to completely replicate real-world browser behavior, not least because different browsers respond to the keyboard in different ways (not to mention non-visual browsers).
If you absolutely want something that isn’t a link but can be activated with the mouse or keyboard, a button type=”button”> (or an input type=”button”> for simple textual contents) is the way to go. If you like, you can always use CSS to restyle it to look more like a link than a button. But, because it acts like a button, that’s how you should truly mark it up.
Answered by bobince
It implies that it will do nothing. It’s a deliberate attempt to make the link ‘travel’ nowhere. However, this is not the proper method.
In fact, you should just return false in the onclick event, as follows:
<a href="#" onclick="return false;">hello</a>
<a href="backup_page_displaying_image.aspx" onclick="return coolImageDisplayFunction();">hello</a>
Answered by Noon Silk
Why do we require href when onclick can accomplish the job just fine? Because the cursor changes to a caret () instead of a pointer () when users hover over the text ‘Print’ when there is no href. Only the presence of the href attribute on an a tag qualifies it as a hyperlink.
Answered by Huy – Vuong Do Thanh
If you’re developing dynamic pages, this is crucial since users don’t want to be taken back to the top every time they click a link.
Answered by Salvin Francis