I have about 40 links which are all handled within jquery but when they are clicked it moves the page position to the top. Is there a better way to stop this happening without giving each one an event handler then doing e.preventDefault() ? Even if I could just include it in the function that is executed without doing return false as that never seems to work for me.
I have about 40 links which are all handled within jquery but when they
Share
Rather than applying
e.preventDefaultto each one individually, you can apply it to them all in one function by using jQuery’s powerful matching features.This code will match all
<a>tags with theirhrefattribute set to#.