javascript - Can I create an html link to the current page without refreshing to the top? -


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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -