ponjoh ponjoh - 1 year ago 66
Javascript Question

Increase the value of a number in an element every x milliseconds

So I have this simple HTML:

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

I want the number 0 to increase by 1 every x milliseconds. How do I do that with Javascript (with or without jQuery)?

Thanks a bunch - I'm new to this :)

Answer Source

You should do this:

   setInterval(function () {
     var value = parseInt($('#badge').html());
}, 1000);


Assuming 1000 milliseconds.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download