-2

Is

<a href="javascript:;">..</a> and <a href="#"> .. </a> do same work.

I saw the first one lot of times and generally i use the second one. Can some one differentiate these two?

G.L.P
  • 7,119
  • 5
  • 25
  • 41

1 Answers1

4

No, they are two different things:

<a href="javascript:;">..</a> is javascript that does nothing.

<a href="#"> .. </a> is an anchor tag that takes the user to the top of the page.

Syntactically they both work, semantically they are both wrong (assuming your intended purpose is not to link the user to the top of the page). Semantically, an anchor tag shouldn't be used if you aren't linking to something.

Further discussion on this topic can be found here: What does href expression <a href="javascript:;"></a> do?

Community
  • 1
  • 1
xengravity
  • 3,501
  • 18
  • 27
  • 1
    I agree but unfortunately it's a pretty common pattern (empty anchor), ebforced by some css/js libraries. It's also a way to disable links on older browsers (or with a pure js approach). Js *version* has also another use: it will not affect browser **history** and won't move to page top when clicked (and other dirty uses too, for example user won't see linked URL and it may be pre/post processed in an Ajax call). – Adriano Repetti Mar 25 '15 at 07:22