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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:13:17+00:00 2026-06-17T22:13:17+00:00

Someone know if after I displays an HTML page I can access a specific

  • 0

Someone know if after I displays an HTML page I can access a specific ID (getElementById), and change it a value several times?

I want to present a client-side some string and change it several times according the progress of the program, but I can not, it writes to me only recently.

For example:

<script type="text/javascript">
  function foo(){
   for(var i = 0; i<10000; i++){
     document.getElementById('myTag').innerHTML = i;
   }
  }
</script>

In this case, I do not see the numbers run. I see only the last one.

If I put alert inside the loop – the value is changed.

  • 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-17T22:13:19+00:00Added an answer on June 17, 2026 at 10:13 pm

    You’re almost there. The only thing you’re doing wrong is replacing the innerHTML content instead of adding to it. Change this:

    document.getElementById('myTag').innerHTML = i;
    

    to this:

    document.getElementById('myTag').innerHTML += i;
    

    Additional/alternative answer:

    Wait. I’ve just reread your question and realized that there is another way of interpreting it. The way you ask it is quite vague so I’m leaving the above answer as is.

    The reason you don’t see “running numbers” as you process the for loop is because you misunderstand how javascript works in the browser.

    The browser’s event loop runs something like this:

    1. Fetch content
    2. Run javscript
    3. Render content
    then repeat forever
    

    This is how javascript works. So running a simple for loop like you’re doing. The browser executes the script until there is nothing else to execute (step 2). Once javascript have finished executing then it will start the render process (step 3). Obviously, by this time the value of i is the final value and therefore you only see the final value.

    The browser never interrupts running javascript to render/update the page. So, how do people implement countdown timers etc? They do it by scheduling a piece of javascript to execute in the next iteration of the event loop. That is to say, the let the browser enter step 3 and at the appropriate moment as the browser enters step 2 again they run the script they want.

    Javascript basically provides two ways to do this: setTimeout and setInterval.

    How setTimeout works is this:

    step 1. nothing to do
    step 2. setTimeout schedules a piece of javascript to run at a later time
            Note that the javascript does not execute yet until setTimeout
            expires.
    step 3. let the browser update the page
    many, many loops of steps 1-3
    step 2 (some time later).
            setTimeout expires and the piece of javascript executes
    step 3. let the browser update the page
    

    So, the get the effect you want, you need to do it like this:

    function foo(){
      var i = 0;
      var update = function(){
        document.getElementById('myTag').innerHTML = i;
        i++;
        if (i<10000) {
          setTimeout(update,100);
        }
      };
      update();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does someone know why i never get the first value of my array? it
Does someone know of a Sqlite manager that I can put on my site,
I wonder if someone can help me. I know JS quite well but am
Someone know some interesting and complete tutorial about how to create a Parent-Child dimension
Could someone know where is saved path to external XML-File that contain configuration for
Does someone know a simple way to set the default zoom and latitude/longitude with
Does someone know how to find the longest common subsequence of a set of
does someone know how to draw 3D surfaces and hide the invisible lines? I
Does someone know or have an idea of how to reload the contents of
Does someone know why this is not a strict quine ? _0='_0=%r;print _0%%_0';print _0%_0

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.