Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Wait Before Continuing</title> <script> function doStuff(){ // Code to run before the pause var hintDiv = document.getElementById("hint"); hintDiv.insertAdjacentHTML('afterbegin', '<p>An alert will be shown in 3 seconds.</p>'); setTimeout(function(){ // Code to run after the pause alert("This is really slow!"); }, 3000); // This will also run before alert hintDiv.insertAdjacentHTML('beforeend', '<p>Alert is coming. Please do not go!</p>'); } </script> </head> <body> <div id="hint"></div> <button type="button" onclick="doStuff()">Run Script</button> </body> </html>