The following works correctly:
alert("start");
loadData();
alert("finished");
loadData () is a method that inserts large amounts of data into a table in the DOM and takes a few seconds.
This, however, does not work properly:
document.getElementById("mydiv").style.display = "block";
loadData();
document.getElementById("mydiv").style.display = "none";
Data is loaded into the table without displaying mydiv until the download is complete, and then mydiv is quickly displayed and disappears.
But this works as intended:
document.getElementById("mydiv").style.display = "block";
alert("start");
loadData();
alert("finish");
document.getElementById("mydiv").style.display = "none";
mydiv is displayed, a warning dialog is displayed, the data is loaded into the table, and then mydiv disappears, as expected.
Does anyone know why the second section of code above is not working correctly?
source
share