Using an anchor as a javascript action, what should the link be?

I've seen (and used) code to have a link spawn a javascript action many times in my life, but I've never come to a firm conclusion on if the href attribute should be blank or #. Do you have any preference one way or the other, and if so, why?

<a href="" onclick="javascript: DoSomething();">linky</a>


<a href="#" onclick="javascript: DoSomething();">linky</a>


You must have something for the href attribute, otherwise the browser will not treat it as a link (for example, making it focusable or giving it an underline) - that's why the use of "#" has become prevalent.

Also, the contents of the event attributes (onclick, onmouseover, on...) are already treated as javascript: you don't need to preface it with javascript:

So given your example, the best way to do that inline (which itself is not the best way, probably), is like this:

<a href="#" onclick="DoSomething(); return false">linky</a>

Need Your Help

How to cleaning hadoop mapreduce memory usage?

hadoop memory mapreduce jobs yarn

I want to ask. I can say for example I have 10 MB memory on each node after I activate process. So, I run the namenode, datanode, secondary namenode, dll. But after I've done the hadoop

Declaration of a VAR on Node.js

javascript node.js express

I am learning Node.js. On the book I am using there is a line that I am not sure I know exactly how it works and was looking for confirmation.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.