Warning: filemtime() [function.filemtime]: stat failed for 71ba5704c07aec55402cb7d674cb5783 in /home/nomadjourney/www/nomadjourney_com/index.php on line 8

Warning: curl_exec() has been disabled for security reasons in /home/nomadjourney/www/nomadjourney_com/index.php on line 8

Warning: curl_exec() has been disabled for security reasons in /home/nomadjourney/www/nomadjourney_com/index.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at /home/nomadjourney/www/nomadjourney_com/index.php:8) in /home/nomadjourney/www/nomadjourney_com/index.php on line 8
Go to top of page using jQuery | Nomad Journey
Skip to content
Sep 18 / Nizam Sayeed

Go to top of page using jQuery

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');

12 Comments

  1. Blockstopper / Dec 12 2009

    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

    • dVICIOUS / Jul 26 2011

      Try
      $(“h3”).click(function(){
                $(‘html, body’).animate({ scrollTop: 0 }, ‘slow’);
      })

      That should work. Although that would make all h3 things take the user to the top of the page. Pehaps give your item the ID “TopPage” then instead of $(‘h3’) you could use $(‘#TopPage’)

      Urgh just found the reply button

  2. Jisjad / Jul 4 2010

    Thank you.

  3. Canmasu / Sep 25 2010

    thanks this is cool. workable code

  4. Nicole / Oct 12 2010

    That was exactly what I needed, thanks so much!

  5. cerah / Dec 9 2010

    Can you please tell me that how can i scroll to particular div using .scrollTop.

    Thanks

    • cabal / Feb 20 2011

      $(“.yourElementClass”).click(function(){
      $(‘.yourDivName).animate({ scrollTop: 0 }, ’slow’);
      });

  6. Mahmud Ahsan / Feb 15 2011

    Just found the trick. Thank You.

  7. Craig Kelley / May 19 2011

    Perfect! Thanks.

  8. dVICIOUS## / Jul 26 2011

    #Blockstopper
    Try
    $(“h3”).click(function(){
              $(‘html, body’).animate({ scrollTop: 0 }, ‘slow’);
    })

    That should work. Although that would make all h3 things take the user to the top of the page. Pehaps give your item the ID “TopPage” then instead of $(‘h3’) you could use $(‘#TopPage’)

  9. Curve1322 / Sep 8 2011

    THANK YOU SO MUCH!!!!!! THIS worked like a charm!!!!!!!

  10. Gerardo Perrucci / Nov 30 2011

    Thanks I was looking one easy solution and find it here.
    Gerardo

Comments are closed.