javascript - Can I create an html link to the current page without refreshing to the top? -
this question has answer here:
i have javascript fade function implemented banner div when clicked, current banner image faded one. html link tag calling function follows:
<a href="#" onclick="fade('bannerdiv');"> <div id="bannerdiv"> <img src="banner_image.gif" /> </div> </a>
the problem is, banner located towards middle of page (middle between top , bottom, not left , right) , when click on banner change image, brings me top of page. there way can fix this?
the proper way make browser not evaluate href parameter @ - javascript:void(0)
, similar targets ugly hack.
you can return false
in onclick event:
<a href="#" onclick="fade('bannerdiv'); return false;">
it idea put actual link current file in href doesn't cause problems if people don't have javascript enabled. however, #
fine that, too.
Comments
Post a Comment