Home » Development

Scroll to the Top of a Div in an HTML Document in Javascript.

11 January 2011 15,749 views 6 Comments Permanent Link
You may sometime want your Brwoser to scroll to a part of the HTML Document.

Typically when you load some content uisng AJAX, you would want to srcroll to the element which was updated.

You can do this with the following javascript code.

document.scrollTo(0, document.getElementById('id-of-element').offsetTop);

Enjoy Coding.

pixel Scroll to the Top of a Div in an HTML Document in Javascript.

PR: 0

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
  • http://bijayrungta.com Bijay Rungta aka @rungss

    Use this to do this in JQuery Native.

    $('html, body').scrollTop($('#id-of-element').offset().top);

  • http://bijayrungta.com Bijay Rungta aka @rungss

    Use this to do this in JQuery Native.

    $('html, body').scrollTop($('#id-of-element').offset().top);

  • http://anjanesh.com Anjanesh Lekshminarayanan

    Shouldn't this be window.scrollTo ?

  • http://www.seasonalworld.com/ swimming pool liners

    Once you know whether you should be looking at beaded pool liners or overlap pool liners, the next step is to determine what size and shape your new liner needs to be in order to fit your pool. Most retailers offer both types of liners for round above ground swimming pools and oval above ground swimming pools. To determine the proper size for your beaded or overlap liner, simply check the specifications in the material that came with your pool when you purchased it or use a measuring tape to carefully measure on your own.

  • http://www.seasonalworld.com/ pool liner

    In doing any replacement, make sure that you drain all pool water and remove all coping clips, top cap and stabilizer rails. Any repairs can then be made and all sand added to its desired level. Your last step is to install the new pool liners in such a manner depending on what kind you have. When using a dry, chlorine-based swimming pool sanitizer, don't forget to always add it to the pool.  Remember also to inspect your pool's filter.

  • Alexandra_rv

    In jQuery it’s just:
    $(‘#id-of-element’).scrollTop(0);