tonyf
tonyf

Reputation: 35557

Programmatically call anchor tag to Page Top at load time

I have a anchor tag that when you click on the "Up to the Top", it will move the web page to the top of the page. My anchor tag is #PAGETOP.

My question is, I am using the jQuery UI Dialog and basically would like to programmatically activate this #PAGETOP anchor so whenever the page always loads at startup, would like to ensure that the page moves immediately to the top of the page.

I would like to emulate the way stackoverflow moves to the top of all your questions when you paginate to the next page (if possible).

Thanks.

Upvotes: 2

Views: 2008

Answers (2)

wiifm
wiifm

Reputation: 3798

Or take @Kip's idea and go pro with the scrollTo jQuery plugin. This plugin has additional options for different animations etc

<script>
     $.scrollTo( "#PAGETOP", 1000 );
</script>

Upvotes: 2

Kip
Kip

Reputation: 109413

To move to the 'PAGETOP' anchor in Javascript, use this:

location.hash = 'PAGETOP';

If you're wanting to do it on page load, in jQuery it'd be like this:

$(function() {
  location.hash = 'PAGETOP';
});

Upvotes: 6

Related Questions