1

I've downloaded a wonderful template and I made some changes to it.

The problem is when I click on some links it automatically scrolls up.

How can I prevent it from scrolling up?

3

2 Answers 2

1

The only reason why a page would scroll up on a click of a link is because of the anchors... Please check your links' href, and make sure they do not contain a # . Usually, downloadable templates use placeholder links and put just the # inside the href so it acts like a link but points to the top of the page.

Sign up to request clarification or add additional context in comments.

3 Comments

It is a correct investigation but incomplete answer. The full answer is given by Roko
@mplungjan IMO, preventing the defaults on a click of a #'d anchor is a band aid solution. Removing the # is the only real solution...
I am not a purist. The "#" has been used by millions to denote a placeholder for links that execute script so it does not give error when clicked and to get a pointer for free. I am by the way not convinced that removing the # will make a difference since the link will then likely load "/" instead but I have not tested that
1

You can event.preventDefault on every anchor that has hash # as href:

// Remove after testing
$("[href='#']").click(function( e ){
   e.preventDefault();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.