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 8555521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:08:28+00:00 2026-06-11T15:08:28+00:00

I want to scroll to a position in a div, when returning back to

  • 0

I want to scroll to a position in a div, when returning back to the page of the div.
So, when I click an item in a list, the id of that item is for example 223.
When returning back to the page, scrollTop has to go to the same position as clicked before.

I save the id of the item in a cookie.

Here is my code:

$(function () {
    var id = $.cookie('LastPositionCookie');
    var rowPos = $("#" + id).position();

    if (rowPos != null) {
        $('#tableBodyRes').scrollTop(rowPos.top);
    }
    else {
        alert(id + " " + rowPos + " error.");
    }
});

The scroll works fine, but it scrolls from the top of the page, not from the div (tableBodyRes). How can I fix this?

EDIT: added a picture with information

enter image description here

Here you can see on the left my div with an overflow. And on the right the normal overflow of my browser. I need to go to the green item when I return to this page again.

Thanks

  • 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-11T15:08:29+00:00Added an answer on June 11, 2026 at 3:08 pm

    To scroll the page to the top of an element,

    // Swap ...
    $('#tableBodyRes').scrollTop(rowPos.top);
    
    // With ...
    $('body').scrollTop(rowPos.top);
    

    EDIT

    For future reference, the issue at hand is scrolling an inner element to a position relative to the parent element (parent has overflow:hidden;), not relative to the document itself.

    The solution we came up with was to take the inner element’s top position and subtract from that the top position of the parent element.

    Relevant jQuery

    var rowPos = $("#336").position();
    var divPos = $("#tableBodyRes").position();
    
    var newTop = rowPos.top - divPos.top;
    
    $('#tableBodyRes').scrollTop(newTop);
    

    HTML

    <div id="tableBodyRes" class="tableBodyDiv clearfix">
        <table id="tableReservations">
            <tr id="335"><td>335</td></tr>
            <tr id="336"><td>336</td></tr>
            <tr id="337"><td>337</td></tr>
        </table>
    </div>
    

    And a jsFiddle for good measure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my list control has its content height as I don't want scroll
After calling notifydatasetchanged(); I want to scroll to the bottom of list so that
Possible Duplicate: JavaScript: Scroll Position of div with “overflow: auto” Hi, i want to
I've got a div that I want to position at the bottom of the
I have a div that I want to 'smart scroll' up and down with
I got a floating header div that follows my scroll position. my problem is
I have a DIV I want to scroll with the page but it's not
I have a div element that I want to move with the page for
I want to scroll down the page to a certain point (height of #first_column
I want to scroll listview.But Listview only scrolls when item of listview exceeded the

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.