title: Animate number incrementing
body: <p>I'm trying to make a simple Javascript animation that increments a number until it reaches the target number. The way I'm doing it right now doesn't work however.</p>
  
  <p>Here is my code: <a href="http://jsfiddle.net/nLMem/4/" rel="nofollow">http://jsfiddle.net/nLMem/4/</a></p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div id="number"&gt;5&lt;/div&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>$(document).ready(function() {
      var target = 50;
      var number = $('#number').text();
  
      while(number &lt;= target) {
          setTimeout(function() {
              $('#number').text(++number);
          }, 30);
      }
  });
  </code></pre>