I have a jquery app which consist of a table. The table has a time field and some number fields. I want to basically increment the values every 3 seconds. So i was thinking of c
Here is a way. Add classes to the cells that need updating:
Lebron James
08:00
27
11
10
In this example, the class updateMeInt means it is a simple integer, and updateMeTime means it is a time value.
Then your update function would iterate through each cell with these classes and increment:
function UpdateFunction(){
$(".updateMeInt").each(function(index){
var cur = parseInt($(this).text(), 10);
$(this).text(cur + 1);
});
$(".updateMeTime").each(function(index){
var cur = $(this).text().split(":");
var sec = parseInt(cur[1], 10);
var min = parseInt(cur[0], 10);
sec = sec + 3;
if (sec >= 60){
sec = 0
min = min + 1;
}
$(this).text(pad(min) + ":" + pad(sec));
});
}
Updated FIDDLE