title: variable wont save in same function jquery
body: <p>I'm trying to sum dynamically created inputs but when i delete some of the inputs just to subtract its value from the var.and when i alert the variable current its NaN</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
    current = 0;
    var max = 3;
  
    $(".inputs").on('keyup', '.field', function(e) {
      if ($('.field').val()) {
        current = current + parseInt($(this).val());
        if (current &lt; max) {
          $(".inputs").append('&lt;div&gt;&lt;input type="text" class="field" name="dynamic[]" value="" /&gt;&lt;/div&gt;');
        }
        if (e.keyCode == 8) {
          current = current - parseInt($(this).val());
          console.log(current);
        }
      }
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div&gt;
    &lt;form&gt;
      &lt;div class="inputs"&gt;
        &lt;div&gt;
          &lt;input name="dynamic[]" id="field" class="field" value="" type="text"&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;input name="submit" class="submit" value="Submit" type="button"&gt;
    &lt;/form&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>