I am creating an app with Phonegap and JQuery Mobile and have a particular scenario where I need to format a particular counter.
Basically the counter starts from 1 and keeps increasing when a certain event is triggered. However, in order to display it i need to display them as 0001 then once an event is triggered it goes to 0002 …. 0099… 0999… 9999 (max).
So far what I have is outputting the number such as 15, but I cannot find how to put the 00 padding in front so that the value is always displayed as 4 characters.
Can someone help me or direct me to any plugin available?
Thanks!
To format your number, you could do
EDIT following comment :
You can do this :
Don’t forget the second argument to parseInt, the radix, as
parseInt("0009")is0…But I’d suggest to use an id and not a class as selector : this would be faster as you have only one div. So your HTML would be
And your jQuery selector would be
"#eventCount"instead of “.eventCount”.