7
  <a href="javascript:void(0)" id="loginlink">login</a>

I've seen such anchor tag's href property having javascript:void(0) value many times. I don't know what exactly that means.I saw this when working with angular 5. Why is javascript:void(0) used as a value for href property?

0

1 Answer 1

14
javascript:void(0)

The snippet show above simply ignores the link "click." This can be done in a similar fashion by the following:

<a href="#" onclick="return false;">link</a>
Sign up to request clarification or add additional context in comments.

2 Comments

This answer doesn't really define why people are using javascript:void(0). The simple answer is that javascript via a framework such as Angular, React, or Vue usually have click handlers that don't properly address the browser wanting an href. The browser won't treat the link as a clickable link unless it has the href. Therefore, people started putting href="<please for the love of...>", and substituting it rather than changing CSS etc. The reason people DON'T want to use a # is because it's treated AS A ROUTING MECHANISM in these, not just a 'scroll here!' on the same page link...
Alternatively use onclick="event.preventDefault()"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.