Reputation: 49384
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
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
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
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
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