I have a simple javascript loop, as you saw below:
function runCode() {
$("#sample-span").removeAttr("style");
for (var i = 0; i < 100000; i++) {
console.log(new Date());
}
$("#sample-span").toggleClass("colorized");
}
This is the span class switch on the page as shown 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 starts, the page freezes and cannot see that the color of the range changes.
How can I solve this problem?
jsfiddle link
UPDATE
Dear, console.log(new Date());
this is just a sample, you assume that heavy javascript projects work here.
source
share