I have a link that I want to click in order to trigger a piece of jQuery code.
I currently have
<a href="#" id="foo">Link</a>
and
$('#foo').click(function(){
which works well. But I always hated using a hash that way. The page flicker and hash are added to the page URL.
One option is to use
<a href="javascript:void(0);" id="foo">Link</a>
but I also donβt like to see this piece of code in the browser status bar. It looks sticky.
What I would prefer is an explanatory javascript placeholder that does nothing, e.g.
<a href="javascript:zoom();" id="foo">Link</a>
which actually works, but throws a ReferenceError in the javascript console since there is no such function. What is the minimum definition of a function that does nothing?
Are there any other alternatives?
Should I just skip the link and use something like
<span id="foo" style="cursor:pointer;cursor:hand;">Link</span>
instead
Mattis
source share