Name

Window.setInterval( ): periodically execute specified code — JavaScript 1.2:

Synopsis

window.setInterval(code, interval)

Arguments

code

A function to be periodically invoked or a string of JavaScript code to be periodically evaluated. If this string contains multiple statements, they must be separated from each other by semicolons. In IE 4 (but not later versions), this argument must be a string.

interval

The interval, in milliseconds, between invocations or evaluations of code.

Returns

A value that can be passed to Window.clearInterval( ) to cancel the periodic execution of code.

Description

setInterval( ) repeatedly invokes or evaluates the function or string specified by code, at intervals of interval milliseconds.

setInterval( ) returns a value that can later be passed to Window.clearInterval( ) to cancel the execution of code.

setInterval( ) is related to setTimeout( ). Use setTimeout( ) when you want to defer the execution of code but do not want it to be repeatedly executed. See Window.setTimeout( ) for a discussion of the execution context of code.

See Also

Window.clearInterval( ), Window.setTimeout( )

Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.