Skip to content

Instantly share code, notes, and snippets.

@KartikTalwar
Created April 5, 2012 00:12
Show Gist options
  • Save KartikTalwar/2306741 to your computer and use it in GitHub Desktop.
Save KartikTalwar/2306741 to your computer and use it in GitHub Desktop.
Make a JavaScript function repeat every x seconds
function refreshData()
{
x = 5; // 5 Seconds
// Do your thing here
setTimeout(refreshData, x*1000);
}
refreshData(); // execute function
@ymaallem
Copy link

ymaallem commented Feb 2, 2021

how can i add document.getElementById("myId").innerHTML=myValue;?
if i have added this into this function, i has stopped working. Can someone help me?

You have to create a variable outside your function and pass it as a parameter and then update it inside the function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment