Satch3000
Satch3000

Reputation: 49384

Internal Link Force scroll to top of page

I have some internal link which shows different content.

Everytime I click the internal links the browser scrolls to a position.

What I need to do is to force it to scroll to the top.

For example:

<a href="#show_area_1">Click Here</a>

It will show a certain div which is fine but I also need it to scroll to the top.

Is this possible?

Upvotes: 2

Views: 2578

Answers (4)

ianbarker
ianbarker

Reputation: 1254

Not sure of the exact methods right now, but something like this should work:

$('a').on('click', function(e) {
 e.preventDefault();
 // do your js stuff
 $(window).scrollTop(0);
});

Upvotes: 3

user100943
user100943

Reputation:

If you're just trying to link to the top of the page,

<a href="#">Back to Top</a>

should do the trick.

Upvotes: 0

ted.goodridge
ted.goodridge

Reputation: 150

Sorry, the link doesn't work (if it was meant to be a link).

A little clarification--Are you trying to get the window to scroll the div to the top of the view, or have the window remain scrolled to the top of the viewport?

A link or code sample would be helpful...

Upvotes: 0

Deleteman
Deleteman

Reputation: 8700

Do your links have JS code associated to the click event? Maybe you're stoping it's propagation and that is why they don't scroll your page.

If your link has an href value of "#" and you don't stop the propagation of the event (either by returning FALSE from your handler method or by using the stopPropagation method), then you should be set...

Upvotes: 0

Related Questions