Here is the sequence I want to achieve:
- Show a div element with the CSS class yellow
- Execute a function for about 5 seconds
- Remove the yellow class and add the green CSS class "state Ok"
However, when running my code, the div container does not appear until after the function has finished. What am I missing?
function sleepFor(sleepDuration) {
var now = new Date().getTime();
while (new Date().getTime() < now + sleepDuration) { /* do nothing */ }
}
function DoIt() {
$('#divState').show(100, function() {});
sleepFor(1000);
$("#divState").removeClass("Yellow").addClass("Green");
}
div {
display: none;
}
div.Green {
border: 1px solid black;
background-color: #93EEAA;
}
div.Yellow {
border: 1px solid black;
background-color: #FFEE99;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" class="button" onclick="DoIt()" value="run" />
<div class="Yellow" id="divState">Some Text</div>