Javascript Sleep Function

I want a sleep function in javascript.

In Javascript, it is setTimeout().

setTimeout() – executes a code some time in the future

Syntax: var t=setTimeout(“javascript statement”,milliseconds);

Here is the code for a simplest example.

<html>
	<head>
	<script type="text/javascript">
	function timedMsg()	{
		var t=setTimeout("alert('5 seconds!')",5000);
	}
	</script>
	</head>
 
	<body>
		<a href="#" onClick="timedMsg()" />
	</body>
</html>

Related posts: