1. Home
  2. Javascript
  3. Set interval
#javascript#loop

Allows to run a function in regular intervals. The second argument takes the interval time in milliseconds. The example checks for the existence of the class before stopping the loop.

var checker = setInterval(function() {
    if (document.querySelector('.sc')) {
       console.log('Fount it!');
       clearInterval(checker);
    }
 }, 100);
copy
Full Javascript cheatsheet
Sitemap Git repository