Today in this post we are going to share, How to make a function that can run every second or run in every specific second in Javascript.

This is very simple and easy to implement. It is very useful if you want to run any block of code every second.

Also attaching a brief explanation video for running a function at a specific time interval.

First, you need to make a simple function and add the codes to whatever you want to do. Then use the “setInterval()” predefined function with its parameter, In the below paragraph, given the example of calling the setInterval function.

<body>
    <h1>Use of <b style="color:red">setInterval</b> function</h1>
    <br><hr>
    <p id="display"></p>



<script>
    setInterval(counter, 1000);
    var i=1;
    function counter(){
    document.getElementById("display").innerHTML +=i+"<br>";
    i++;

    }
</script>

</body>
</html>

How to call a function every 10 seconds javascript

Leave a Reply

Your email address will not be published.