Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 1000
AliRıza Adıyahşi Avatar asked Nov 23 '12 07:11

AliRıza Adıyahşi


2 Answers

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

like image 135
Mohammed H Avatar answered Oct 17 '22 05:10

Mohammed H


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();
});
like image 32
Blender Avatar answered Oct 17 '22 05:10

Blender