jQuery hyperlinks - href value? text][1]
I am running in to a problem using jquery and a click event attached to an anchor element. [1]: 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With