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

  • Home
  • SEARCH
  • 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 7970991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:32:06+00:00 2026-06-04T07:32:06+00:00

I have div with vertical scroll bar. Div is being updated dynamically via ajax

  • 0

I have div with vertical scroll bar. Div is being updated dynamically via ajax and html is inserted using jQuery’s .html method.
After div is updated scroll bar returns to top and I am trying to keep it in the previous position.

This is how I’m trying it:

var scrollPos = $('div#some_id').scrollTop(); //remember scroll pos
$.ajax({...
    success: function(data) {
        $('div#some_id').html(data.html_content); //insert html content
        $('div#some_id').scrollTop(scrollPos); //restore scroll pos
    }
});

This fails. My best guess is that it is failing due to inserted html not rendered (ie. no scroll).

For example this works.

setTimeout(function(){
    $('div#some_id').scrollTop(scrollPos);
}, 200);

But this is dirty hack in my opinion. I have no way of knowing that some browsers won’t take more then these 200ms to render inserted content.

Is there a way to wait for browser to finish rendering inserted html before continuing ?

  • 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-04T07:32:08+00:00Added an answer on June 4, 2026 at 7:32 am

    It’s still a hack, and there really is no callback available for when the HTML is actually inserted and ready, but you could check if the elements in html_content is inserted every 200ms to make sure they really are ready etc.

    Check the last element in the HTML from the ajax call:

    var timer = setInterval(function(){
       if ($("#lastElementFromAjaxID").length) {
           $('div#some_id').scrollTop(scrollPos);
           clearInterval(timer);
       }
    }, 200);
    

    For a more advanced option you could probably do something like this without the interval, and bind it to DOMnodeInserted, and check if the last element is inserted.

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

Sidebar

Related Questions

Hi I have the container div set for displaying horizontal and vertical scroll bar
I have a div with overflow: auto (a vertical scroll bar appears if the
I have a GridView in a div with Vertical scroll, but I want to
I have a big table with vertical scroll bar. I would like to scroll
I have a jquery ui draggable div, and the HTML contents do not behave
Suppose I have the following html: <div style=width:200px;height:200px;overflow:scroll> ... </div> If the stuff in
I recently asked how to hide the vertical scroll bar using overflow:hidden . While
I have a div and it has a scroll bar here is the code
I have a div in which I need a permanent vertical scrollbar. Sometimes the
i have problem with image vertical-align in div .img_thumb { float: left; height: 120px;

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.