Javascript is single threaded. There is only one thread that can ever access a page.
In some HTML5 browsers, you can use Web Workers to execute some code on another thread, and then exchange messages with the main thread through messaging, but the Web Worker stream cannot access the DOM in any way.
If you want counters to be executed in a loop, a typical way to do this is to use timers, and then set the contents of the object in the DOM every time a timer runs. Thus, you may have several things running at the same time, but in reality they are still one at a time, just separately.
Here is an example of two counters that βappearβ at the same time: http://jsfiddle.net/jfriend00/3yc9r/ .
The code for this (runs after the page loads):
var cntr1 = 1; var cntr2 = 2; setInterval(function() { document.getElementById("time1").innerHTML = cntr1 += 13; }, 33); setInterval(function() { document.getElementById("time2").innerHTML = cntr2 += 5; }, 44);
Also, you really don't want to do document.write() in a loop. Code that will run for a while should run after the page loads and should modify objects directly in the DOM, rather than using document.write() .
source share