![]() ![]() SetTimeout() accepts time in milliseconds, so setTimeout(fn, 1000) tells JavaScript to call fn after 1 second. What code should wait 5 seconds if you mean the HTML code to display after 5 seconds, set its CSS display to none and after 5 seconds set it to the previous value (an empty string. A strong note to put out there: the above code does not guarantee a perfect sleep. ![]() Note how I wrote about 5 seconds, and not 5 seconds. To delay a function execution in JavaScript by 1 second, wrap a promise execution inside a function and wrap the Promise's resolve() in a setTimeout() as shown below. This function performBatchActions, when called, simply executes the performAPIRequest function, waits about 5 seconds, and then calls the same function again. ![]()
0 Comments
Leave a Reply. |