Categories
How To Article Javascript

How to use time function in javascript

How to use time function in javascript

In JavaScript, we are able to execute some code after a specified time-interval. This is called timing events in javascript.

It’s very easy to time events in JavaScript. The two key methods that are used are:

  1. setTimeout()
  2. clearTimeout()

Code for thr following is:-

<html>
<head>
<script type="text/javascript">
function Timeevent()
{
var t=setTimeout("alertMsg()",2000);
}
function alertMsg()
{
alert("After click displayed in 3 seconds");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click Here" onClick="timeMsg()" />
</form>
</body>
</html>