You can use the 'step' option for the 'animate' function of jQuery to perform an action on each 'step' of the animation.
//When the document is ready..
jQuery(document).ready(function () {
//..loop over all of the INPUT elements that have a non-blank data-value field..
jQuery("input[data-value!='']").each(function (inputKey, inputItem) {
//..animate between the current value of the input (i.e. 0) and the desired
// value specified in the data-value field, setting to the full value upon
// completion of the animation
jQuery({
value: jQuery(inputItem).val()
}).animate({
value: jQuery(inputItem).data("value")
}, {
step: function () {
jQuery(inputItem).val(Math.round(this.value));
},
complete: function() {
jQuery(inputItem).val(jQuery(inputItem).data("value"));
}
});
});
});
Check out this jsFiddle example: http://jsfiddle.net/yE86J/9/1
I'd recommend using rounding to ensure you end up
References: http://www.josscrowcroft.com/2011/code/jquery-animate-increment-decrement-numeric-text-elements-value/, jQuery how to find an element based on a data-attribute value?