3
<a href="javascript:void(0)" onclick="Method1()">Link 1</a>

I realize that the above method of using javascript:void(0) is a bad practice and a better way of handling undefined would be

<a href="#" onclick="Method1()">Link 1</a>

My question is:

Is there ever a situation where we should be using javascript:void(0) as against <a href="#">

user544079
  • 16,109
  • 42
  • 115
  • 171
  • 1
    there is good deal of discussion already on SO here http://stackoverflow.com/questions/1291942/what-does-javascriptvoid0-mean and even http://stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0 – Vinod Louis Jul 22 '13 at 14:11
  • Please see - http://stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0 – Ishan Jain Jul 22 '13 at 14:16

1 Answers1

3

javascript:void(0) is superior to # since it doesn't claim that a suitable fallback (for when the JavaScript fails for any reason) is to scroll back to the top of the page.

Neither are good though, JavaScript should be implemented unobtrusively and progressively.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • So in that case the best way to handle a javascript failure would be javascript:void(0) ? – user544079 Jul 22 '13 at 14:12
  • 1
    No. The best way is with a real link that goes somewhere sensible (such as something that does the same operation server side). – Quentin Jul 22 '13 at 14:13