I have a problem with a simple javascript.
I would like to display a html div for 2 seconds.
I tried the following code but instead of display my div for 2 seconds on execution my div is displayed after 2 second.

```
//show my element
document.getElementById("alertProg").style.display=block;

//wait
var ms=2000;
ms += new Date().getTime();
while (new Date() < ms){}

```

How can I solve this problem?

**EDIT:** the problem isn'nt only in a time delay but if I call a function between the change of display value the div isn't displayed correctly. example:

```
document.getElementById("alertProg").style.display='block';
myFunction();
document.getElementById("alertProg").style.display='none';

```

as result myFunction is executed but alertProg is always hidden.