Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:18:11+00:00 2026-06-12T12:18:11+00:00

I would like to have this little button, when you click on it, a

  • 0

I would like to have this little button, when you click on it, a new table row is added and using the jQuery to smoothly scroll to that newly added row.

I have created an example here http://jsfiddle.net/2EBNH/

Notice that this is a simplified version of my code. The real one allows the row to be added anywhere within the table (doesn’t have to be at the last row), so dont simply tell me I can always scroll to the bottom.

But even just scrolling to the bottom, the code doesnt work. It works for the first 10 rows I assume, but the position/offset (I have tried both) seems not correct if you have more rows added.

To test it, just add more than 15 rows then you will see the result.

I notice that if you move the scrollbar to the top everytime after you clicked on the button, it seems to work somehow.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:18:12+00:00Added an answer on June 12, 2026 at 12:18 pm

    The reason why this isn’t working is the following:

    The position() method returns a relative distance to the top of the window. Since you have limited the size of the div, the distance to the top of the window is not necessarily what you want to measure it against, but you want to measure it against the offset it has against the div that contains it.

    In other words: When the scroll is on top and you add a new element (which goes to the bottom), the offset/position against the window is the same as the amount of pixels you want to scroll, so it works then. However, if you are already scrolled to the bottom, the distance between the element and the top of the window is just around 100px (the height of the div), so it will scroll to 100px, meaning that if the scroll distance is larger than that, it will actually go up.

    You might be interested in checking the ScrollTo jQuery plugin:

    var rownum = 1;
    $('input').click(function () {
        $('table').append('<tr id=row-' + rownum + '><td>' + rownum + ': row</td></tr>');
        $('#row-' + rownum).ScrollTo({
            duration: 400,
            easing: 'linear'
        });
        rownum++;
    });​
    

    Here is your fiddle using the plugin

    Here is a solution WITHOUT using the plugin (and here’s the jsfiddle):

    var rownum = 1;
    $('input').click(function () {
        $('table').append('<tr id=row-' + rownum + '><td>' + rownum + ': row</td></tr>');
        var $row = $('#row-' + rownum);
        var topOffset = $row.parent().parent().parent().scrollTop() + $row.position().top;
        $('div').animate({scrollTop: topOffset + "px"}, 400);
        rownum++;
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table structure and would like to map it using Fluent Hibernate
I have this website iloveforwards.com created using drupal. I would like to have a
I have this scenario where I would like to redirect my domains using the
I would like to have this behavior in a task history stack: First task
I would like to have declaration like this: void Date::get_days_name(const Date& = this) which
I have this function that I would like to condense into some iterator. How
I have this class which i would like to map: public class Contract {
I have this piece of logic I would like to implement as a trigger,
I have this sample string where I would like to replace the star with
I have this array property in my model and would like to see it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.