Use setInterval() to run a piece of code every x milliseconds.
You can wrap the code you want to run every second in a function called runFunction
.
So it would be:
var t=setInterval(runFunction,1000);
And to stop it, you can run:
clearInterval(t);