Auto scroll of page to specific element of HTML

14,500

Solution 1

You can simply assign an id to the span and can redirect to the current page with #your-id attached at the end of your url.

<a href="http://jsfiddle.net/tFcsP/show/#demo">Click to go</a>

Check this link http://jsfiddle.net/tFcsP/show/#demo

Solution 2

Working DEMO

Try this

This will animate towards the required div or span

$(document).ready(function () {
    target_offset = $('#third1').offset(),
    target_top = target_offset.top;
    $('html, body').animate({
        scrollTop: target_top
    }, 800);
});

Solution 3

Using jQuery :

 $(function() {       
     $(window).scrollTop($('#div_name').offset().top);
 });
Share:
14,500
chaman shareef
Author by

chaman shareef

Working as a Java developer from last two years.

Updated on June 16, 2022

Comments

  • chaman shareef
    chaman shareef almost 2 years

    Hi I have length jsp page and at the bottom of the page I have save button once I click the save button it will save the data to the server and once data is saved I load the same page again and I am displaying some information saying "Data is saved" at the bottom of the page.

    My question is how can I load the page to show this message when page loads instead of loading page at its top.

    <html>
    <head></head>
    <body>
    <span> Hi </span>
    .....................
    .....................
    .....................
    .
    .
    .
    .
    .
    .
    //at the bottom of page
    <span> Data Saved succefully</span>
    </body>
    </html>
    

    So when I load the page I should see "Data Saved succefully" message.

  • tetri
    tetri over 10 years
    note that there is no need to use javascript with this solution