AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

Anchor click and keeping page position?

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.

Upvotes: 9

Views: 12788

Answers (5)

Ben
Ben

Reputation: 57209

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.

Upvotes: 4

phschoen
phschoen

Reputation: 2081

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

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

Upvotes: 1

Mohammed H
Mohammed H

Reputation: 7048

<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.

Upvotes: 1

Mahmoud Farahat
Mahmoud Farahat

Reputation: 5475

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

<a href="javascript:void(0)">Anchor</a>

Upvotes: 1

Blender
Blender

Reputation: 298126

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();
});

Upvotes: 19

Related Questions