Possible Duplicates:
What's the effect of adding 'return false' to an onclick event?
When and why to 'return false' in javascript?
I mean, if I have this function :
function openMask() {
alert("enter");
}
is it better call it as :
<a href="javascript:void(0);" onclick="openMask()">Link</a>
or :
<a href="javascript:void(0);" onclick="openMask(); return false;">Link</a>
??? I’m really curious about it! Never understood the difference…
In a DOM event handler (such as
onclick), returningtruemeans “continue with the event”, and returningfalsemeans “don’t”.In this case, it’s not entirely meaningful because your
hrefis alreadyjavascript:void(0)(which won’t do anything).Note, though, that
javascript:URIs should really be avoided, and that this isn’t very helpful for non-Javascript users, so you should provide a fallback page, and then thereturn falsebecomes more meaningful:JS:
HTML: