Why when I try and hid a div for an
operation does it not disappear? It is my understanding that you can hide something using document.getElementById('something').style.display = "none";
. Yet when I try and do an operation in between showing and hiding it, it does not work.
function someComplicatedFunction(ms) {
// This isn't the exact function I am using,
// but it has a similar form and the same problem
let start = new Date().getTime();
let end = start;
while (end < start + ms) {
end = new Date().getTime();
}
}
function hideTheOtherDiv() {
document.getElementById('div1').style.display = "none";
document.getElementById('div2').style.display = "initial";
console.log("Start");
someComplicatedFunction(3000);
console.log("end");
document.getElementById('div1').style.display = "initial";
document.getElementById('div2').style.display = "none";
}
document.getElementById('div2').style.display = "none";
<!DOCTYPE html>
<html>
<body>
<div id="div1">One</div>
<div id="div2">Two</div>
<button onclick="hideTheOtherDiv()">Switch</button>
</body>
<script type="text/javascript">
</script>
</html>