I’m trying to create a simple timer here, but I ran into a problem.
I render the page with a script changing innerHTML, but the innerHTML change only happens after the whole function has finished processing, including the scripts that come after the innerHTML change.
It’s better to demonstrate, so I created a jsfiddle:
I tried to change the position of the display script, and I tried to use callback functions (probably incorrectly), but nothing works.
Can someone please explain why this is happening, and how to fix it?
You can fix it by setting a timeout for your alert, even to 1ms.