I have a simple javascript loop as you seen below:
function runCode() {
$("#sample-span").removeAttr("style");
for (var i = 0; i < 100000; i++) {
console.log(new Date());
}
$("#sample-span").toggleClass("colorized");
}
That toggle class of span in the page as below:
<span id="sample-span" style="color: orange;">Sample Text</span>
<input type="button" value="click to run" onclick="runCode()" />
<style>
span {
color: blue;
}
.colorized {
color: red;
}
</style>
The problem is that when the loop is running the page freezes and can't see that span color changes.
How can I solve this problem?
UPDATE
Dear all, console.log(new Date()); is just a sample, you assume that here is running heavy javascript procces.