Anchor When I click the anchor butt...">

Anchor click and save page position?

My page has an anchor that has no link, for example:

<a href="#">Anchor</a> 

When I click the anchor button at the bottom of the page, the page scrolls up. I want to keep the page position if I click the link. How can i do this. (no js is better for me)

Hope I could explain.

Thanks in advance.

+8
javascript html
source share
5 answers

You still have to use JS, but you can do it inline:

 <a href="javascript:void(0);">Test</a>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ 

Demo: http://jsfiddle.net/7ppZT/

Alternatively, you can record an event:

 $('a[href^="#"]').click(function(e) { e.preventDefault(); }); 
+18
source share

You can place anchors anywhere on the page on which you want.

 <a href="#stophere">Anchor</a> <a id='stophere'>Bottom Of Page</a> 

Then the link will go to the named anchor. Just stick to this element wherever you stay.

+4
source share

to fix this problem, I use this code, this is a script solution, but works on all browsers

 <a href="javascript:void(0)">Anchor</a> 
+1
source share

you need to set the name and add the name after # like this

 <a name="adsf" href="#adsf">Anchor</a> 
+1
source share
 <a href="#noname">Anchor</a> 

Make sure the noname you did not use for the id attribute for any tag or name attribute of tag a .

0
source share

All Articles