English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This is one of many timing events. Thewindowobject allows code to be executed at a specified time interval. The object providesSetTimeout()to execute a function after a certain period of time. It usestwo parametersas a parameter. One isfunction, another isTime, thisTimespecifies the time interval after which the function should be executed.
window.setTimeout(function, milliseconds);
In the following example, the time passed to the setTimeout() function is2seconds. Therefore, the function will execute and display the output after two seconds, as shown in the figure.
<html> <body> <p>wait 2 seconds.</p> <script> setTimeout(function(){ document.write("www.oldtoolbag.com is a great IT technology learning platform"); }, 2000); </script> </body> </html>
wait 2 seconds www.oldtoolbag.com is a great IT technology learning platform
In the following example, the time passed to the setTimeout() function is3Seconds. Therefore, the function will execute and display the output after three seconds, as shown in the figure.
<html> <body> <p id="time"></p> <script> setTimeout(function(){ document.getElementById("time").innerHTML = "www.oldtoolbag.com is a great IT technology learning platform"; }, 3000); </script> </body> </html>
www.oldtoolbag.com is a great IT technology learning platform