Go to top of page using jQuery

2009 September 18
by Nizam

This one liner jQuery snippet will force your browser to go to the top of your page:

$( 'html, body' ).animate( { scrollTop: 0 }, 0 );

If you want to add some smooth scrolling:

$( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
2 Responses leave one →
  1. 2009 December 12

    hiya,

    Do you have to add an element that the user can click on?
    I ask because I have jQuery installed: jquery-1.3.2.min.js
    ..and javScript enabled.

    I have other jQuery effects working on the same page.

    I tried the following:

    TOP

    $(“h3″)
    $(‘html, body’).animate({ scrollTop: 0 }, ’slow’);

    Do you know where I’m going wrong?

    Many thanks,

    Blockstopper

  2. 2010 July 4
    Jisjad permalink

    Thank you.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS