Search code examples
javascriptfunctiontimer

Run a function every 30 seconds javascript


I am trying to run a function every 30 seconds but setInterval waits 30 seconds then runs it repeatedly. So if there are any other methods of going about this. (Without 3rd party plugins)

Any help would be appreciated


Solution

  • Based on the answer from "Schechter" but fixed to run on the first page load and then runs every 30 secs.

    function myFunction(){
        console.log('myFunction Called')
    }
    
    myFunction();
    
    setInterval(function(){
        myFunction()
    }, 30000)