Make sure that href first has a hash # before changing anything so that normal links work anyway.
One way is to check the hash property of an element
if(this.hash){ e.preventDefault(); // rest of code shown }
You can also use the attribute selector to filter only c # links in href
$('body a[href^=#]').click...
The latter assumes all hash links are relative, and href starts with #
source share