Konrad Reiche
Konrad Reiche

Reputation: 29543

Force DOM refresh in JavaScript

I am running a loop within a click event handler doing the following:

The problem is, that the DOM is not refreshed until the loop has terminated. Running the loop for 100 iterations this takes too long, I would like to give a result every time I computed one.

How can I force the DOM to be refreshed?

Upvotes: 4

Views: 3591

Answers (1)

Martin Jespersen
Martin Jespersen

Reputation: 26183

If you are in a browser that supports it, workers are ideal for this situation.

If not, use setTimeout after each computation to break the callstack and allow the browser to use time on rendering.

Upvotes: 4

Related Questions