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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:26:16+00:00 2026-05-28T00:26:16+00:00

I have a javascript function that loads 100 div’s from a xmlhttprequest function. I

  • 0

I have a javascript function that loads 100 div’s from a xmlhttprequest function. I would like it so that the browser shows them loading one by one, and so the user can see the progress. However with the function below I see nothing until everything is loaded. How can I get the browser to ‘redraw’ the page after each child div is attached?

  window.onLoad = function () 
    {
    var i;
    for (i=1;i<=100;i++)
    {
      var newdiv = document.createElement('div');
      newdiv.innerHTML = httpget('getitem.pl?component=' + i);
      var maindiv = document.getElementById('maindiv');
      maindiv.appendChild(newdiv);
      document.getElementById('progressdiv').innerHTML = 'Progress: ' + i + ' of 100';
      }
    document.getElementById('progressdiv').innerHTML = 'Loaded.';
    }
  • 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-05-28T00:26:16+00:00Added an answer on May 28, 2026 at 12:26 am

    You can’t do it within a function. You need to let the browser breathe, normally using setTimeout(fn, 0).

    window.onload = function() {
      var i = 1;
      function loop() {
    
        // loop body
    
        if (++i <= 100) {
          setTimeout(loop, 0);
        } else {
          // loop done
        }
      }
      loop();
    }
    

    Javascript and browser’s UI are running in the same thread; as long as you keep executing JS, the UI will not update. setTimeout will push a new “job” on the queue, and then the loop function will exit. This ends the current “job”. Next in the queue will be any changes in the UI; when that is done, the next loop “job” will commence.

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

Sidebar

Related Questions

I have a Javascript function that is called from the onchange method in a
I have a page that is basically this: <div id=thelist style=height:100%; width:100%></div> <script type=text/javascript>
I have a javascript function that manipulates the DOM when it is called (adds
I have a javascript function that calls a generic function to make an ajax
I have a javascript function that accepts a number and performs a mathematical operation
I have a javascript function that checks for a date range. Is there any
I have a javascript function that is being built to animate the collapse of
I have a javascript function that toggles the display for rows in a table.
I currently have a Javascript function that uses a string to reference an object
I have a javascript function (class) that takes a function reference as one paremter.

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.