Im sure this has been asked 1000 times before, basically all I want to do is change the content of an element of the page to display a loading message while my other javascr
What would be nice if you could do would be to call the showMessage
function asynchronously. In other languages, you could do this with threads, and in HTML5 you can do this with workers, which are designed exactly for this sort of thing, but for right now you can most simply just use setTimeout
, which makes the code in the first argument execute after a certain amount of time, allowing the current code to execute before it does.
Change
onclick="showMessage(); wasteTime();"
to
onclick="showMessage; setTimeout(wasteTime,5);">