Take the 2-minute tour ×

This question already has an answer here:

<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="#">

share|improve this question

marked as duplicate by j08691, Joe Frambach, Pointy, Royi Namir, Molecular Man Jul 22 '13 at 14:12


there is good deal of discussion already on SO here stackoverflow.com/questions/1291942/… and even stackoverflow.com/questions/134845/… –  Vinod Louis Jul 22 '13 at 14:11
Please see - stackoverflow.com/questions/134845/… –  Ishan Jain Jul 22 '13 at 14:16

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
So in that case the best way to handle a javascript failure would be javascript:void(0) ? –  user544079 Jul 22 '13 at 14:12
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
