Search code examples
jquerytimer

How do you make a timer that counts up with jQuery?


How do I make a timer with jQuery that counts up with out plugins or anything like that? I have looked around on multiple sites but I haven't found anything that works. Everything I've found counts down or doesn't work for me. I'm using jQuery 2.1.4.


Solution

  • I am not sure if I am following exactly and you didn't mention your use case, but I think you may find this useful:

    setInterval(function(){ alert("Hello"); }, 3000);
    

    Just replace the alert with your code and it will be run every 3 second. So to make a counter just do I=I+1 inside there.

    Do you need to display the I in html? Then

     $("#yourID").append(I)