After a few years, I decided to dive back into experimenting with JavaScript. I've encountered a situation where I'm trying to add the character "X" to a div
element one at a time, instead of all at once. Currently, the DOM seems to be adding them in clusters, leaving my page blank and then suddenly displaying everything together. My goal is to have the "X's" show up individually with a delay of 2 seconds between each addition.
<div id="here"></div>
<script>
function wait(ms) {
var d = new Date();
var d2 = null;
do {
d2 = new Date();
}
while (d2 - d < ms);
}
function runTest() {
var cnt = 0;
while (cnt < 50) {
var x = document.getElementById("here");
x.innerHTML += "X + ";
wait(2000);
cnt++;
}
}
</script>