Programmatically call the anchor tag to the top of the page at load time

I have an anchor tag that when you click "Up" takes the web page to the top of the page. Anchor tag #PAGETOP.

My question is that I am using the JQuery UI Dialog and would basically like to programmatically activate this #PAGETOP anchor, so whenever the page always loads on startup, you want the page to jump to the top of the page immediately.

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

Thank.

+2


source to share


2 answers


Or take @Kip's idea and walk through with the scrollTo jQuery plugin . This plugin has additional options for various animations, etc.



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

      

+2


source


To navigate to the "PAGETOP" anchor in Javascript use this:

location.hash = 'PAGETOP';

      



If you want to do it on page load, in jQuery it would be like this:

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

      

+6


source







All Articles