0

Hi in my javascript i need to increase an int value by one after every 5 seconds. How to do this? The script should keep increasing until the user moves away from the page.

2
Contributors
2
Replies
6
Views
4 Years
Discussion Span
Last Post by yaragalla_mural
1

This could be easily done using the setInterval() method.

Simple example...

<span id="total">0</span>

<script>
var x = 0;
var int=self.setInterval(function(){count()},5000);

function count(){
  x++;
  document.getElementById("total").innerHTML=x;
}
<script>

Try on jsFiddle

Edited by JorgeM

Votes + Comments
Thanks
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.