How to prevent redirect after hyperlink click?
You can simply remove the href attribute:
<a id='key' onclick="func(0)">foo</a>
Change it to:
vvvvvvv
<a href="#" id=key onclick="return func(0)">foo</a>
Use javascript:void(0);
instead of #
as follows:
<a href="javascript:void(0);" id=key onclick="func(0)">foo</a>