News for hackers. Stuff that matters.
Re:Ask HN: the current state of the empty # in 'a href' by chime on Sunday March 27, 2011 @12:33AM (#2374177)
I use A without href only when I'm making an actual anchor A name. When I use href=#, I always have javascript onclick return false. This won't stop crawlers but it keeps the user's history and address bar clean.
Re:Ask HN: the current state of the empty # in 'a href' by craigkerstiens on Sunday March 27, 2011 @10:34AM (#2375043)
Adding a no follow on the link would stop the crawlers actually. Your current approach with return false and a no follow is the approach I most commonly use. The full result looking like:

    <a href="#" onclick="DoSomeStuff();return false;" rel="nofollow">
Re:Ask HN: the current state of the empty # in 'a href' by jonah on Sunday March 27, 2011 @02:52AM (#2374402)
Another approach is href="javascript:;". Not as nice in your status bar but slightly less code and you don't need a big JS lib to implement it.

(preventDefault is preferable though.)

Re:Ask HN: the current state of the empty # in 'a href' by keyle on Sunday March 27, 2011 @04:17AM (#2374524)
what about href='' and in the jquery onclick function, return false at the end?
Re:Ask HN: the current state of the empty # in 'a href' by chime on Sunday March 27, 2011 @08:02AM (#2374781)
href='' will reload the current page in most browsers if the JS code hasn't loaded yet (waiting for $(function(){}) to fire) or has an error for some reason. href='#' will at least prevent that. Returning false form jQuery works.