setIntervalsetInterval*
*Contents  *Index  *Topic Contents
*Previous Topic: setEndPoint
*Next Topic: setTimeout

setInterval

Description

Repeatedly evaluates an expression after a specified number of milliseconds has elapsed.

Syntax

intervalID = object.setInterval(expression, msec [, language])

ParameterDescription
expression String containing the script code to execute each time the interval elapses.
msec Integer value or numeric string specifying the length of the interval, in milliseconds.
language Optional. String specifying the language in which the code is executed.

Return Value

Returns an integer identifier representing the interval. Use this identifier to clear (stop) the interval.

Example

The following example sets a 5-second interval. Each time the interval elapses, the background color of the document changes.

setInterval("changeColor()", 5000);
   .
   .
   .
function changeColor()
{
  if (document.body.bgColor == "#ff0000")   // Check if body bgColor is red by comparing to hexidecimal value
      document.body.bgColor = "blue";
  else
      document.body.bgColor = "red";
}

Applies To

window

See Also

clearInterval


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.