9

In my page there are some anchor that has no link, like this:

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

When I click anchor that is bottom of the page, Page is scrolling to top. I want to keep page position, if I clicked the link. How Can I do this. (no js is better for me)

I hope, I could explain.

Thanks in advance.

Ben
  • 54,723
  • 49
  • 178
  • 224
AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197

5 Answers5

19

You'll 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 capture the event:

$('a[href^="#"]').click(function(e) {
    e.preventDefault();
});
Blender
  • 289,723
  • 53
  • 439
  • 496
4

You can put anchors in anywhere in the page where you want it to go.

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

<a id='stophere'>Bottom Of Page</a>

Then, the link will go to the named anchor. Just stick in that element wherever you want to stop.

Ben
  • 54,723
  • 49
  • 178
  • 224
1

to fix this issue , I use this code , it's script solution but works on all browsers

<a href="javascript:void(0)">Anchor</a>
Mahmoud Farahat
  • 5,364
  • 4
  • 43
  • 59
1
<a href="#noname">Anchor</a>

Make sure that noname you didn't use for id attribute of any tag or name attribute of a tag.

Mohammed H
  • 6,880
  • 16
  • 81
  • 127
1

you have to set a name and add the name after the # like this

<a name="adsf" href="#adsf">Anchor</a>
phschoen
  • 2,021
  • 16
  • 25