jquery click on anchor element forces scroll to top?

Posted by Dan.StackOverflow on Stack Overflow See other posts from Stack Overflow or by Dan.StackOverflow
Published on 2009-06-30T03:29:23Z Indexed on 2010/04/05 11:13 UTC
Read the original article Hit count: 513

Filed under:
|
|
|
|

http://stackoverflow.com/questions/720970/jquery-hyperlinks-href-value[link text][1]

I am running in to a problem using jquery and a click event attached to an anchor element. [1]: http://stackoverflow.com/questions/720970/jquery-hyperlinks-href-value "This" SO question seems to be a duplicate, and the accepted answer doesn't seem to solve the problem. Sorry if this is bad SO etiquette.

In my .ready() function I have:

jQuery("#id_of_anchor").click(function(event) { //start function when any update link is clicked
		Function_that_does_ajax();
		});

and my anchor looks like this:

<a href="#" id="id_of_anchor"> link text </a>

but when the link is clicked, the ajax function is performed as desired, but the browser scrolls to the top of the page. not good.

I've tried adding:

event.preventDefault();

before calling my function that does the ajax, but that doesn't help. What am I missing?

Clarification

I've used every combination of

return false;
event.preventDefault(); 
event.stopPropagation();

before and after my call to my js ajax function. It still scrolls to the top.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about scroll