How to get jQuery animateNumber to pull value dynamically?
Posted
by
mcography
on Stack Overflow
See other posts from Stack Overflow
or by mcography
Published on 2014-08-21T21:31:00Z
Indexed on
2014/08/21
22:20 UTC
Read the original article
Hit count: 202
I am trying to implement jQuery animateNumber, and I have it working like the demo just fine. However, I want to modify it so that it pulls the number from the HTML, rather than setting it in the script. I tried the following, but it just shows "NAN." What am I doing wrong?
<div class="stat-title animate-number">$16,309</div>
<script>
$('.animate-number').each(function(){
var value = new Number;
// Grab contents of element and turn it into a number
value = $(this).text();
value = parseInt(value);
// Set the starting text to 0
$(this).text('0');
$(this).animateNumber(
{
number: value,
},
1000
)
});
</script>
© Stack Overflow or respective owner