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>
or
<a href='#' onclick='javascript: DoSomething();'>linky</a>
You must have something for the
hrefattribute, 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 withjavascript:So given your example, the best way to do that inline (which itself is not the best way, probably), is like this: