title: How to continuously add to a variable on iteration of a for-loop, with jQuery?
body: <p>I'm trying to increase a number on each iteration of a <code>for</code> loop, in jQuery (1.4.2), by the width of the previous element.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>var
  $lis = $('#bookmarks &gt; li'),
  liHeight = parseInt($lis.height()),
  numLis = $lis.length;
  console.log(numLis);
  
  var totalLeft = '0';
  console.log(totalLeft);
  
  for (i=1; i&lt;numLis; i++) {
      var leftOffset = $lis.eq(i-1).width();
      var leftTotal = leftOffset + leftTotal;
  
  
      console.log(leftOffset +"/"+ leftTotal);
  }
  </code></pre>
  
  <p>The output from this section is:</p>
  
  <pre><code>11 (the length of the array)
  0 (the initial value of 'totalLeft')
  97/97
  117/214
  90/
  115/NaN
  101/NaN
  138/NaN
  93/NaN
  96/NaN
  102/NaN
  80/NaN
  </code></pre>
  
  <p>I've tried using <code>parseInt()</code> around one, and both, variables in the <code>var leftTotal = leftOffset + leftTotal;</code> variable assignment, to no avail. I've also tried using jQuery's <code>each()</code>, with the exact same result. Which is unsurprising, since I assigned the values in almost exactly the same way...</p>
  
  <p>There are two questions here:</p>
  
  <ol>
  <li>Why is <code>leftTotal</code> not-a-number (<code>NaN</code>)?</li>
  <li>How can I add the <em>new</em> value of <code>leftOffset</code> to the previous-iteration's value of <code>leftOffset</code>?</li>
  </ol>
  
  <p>The console log <em>should</em> read something like:</p>
  
  <pre><code>11
  0
  97/97
  117/214
  90/304
  115/419
  101/520
  138/658
  93/751
  96/847
  102/949
  80/1029
  </code></pre>
  
  <p><hr />
  <strong>Edited</strong> in response to @KennyTM:</p>
  
  <p>Console.log output is now (more promising):</p>
  
  <pre><code>11
  0
  97 "/" "970"
  117 "/" "117970"
  90 "/" "90117970"
  115 "/" "11590117970"
  101 "/" "10111590117970"
  138 "/" "13810111590117970"
  93 "/" "9313810111590117970"
  96 "/" "969313810111590117970"
  102 "/" "102969313810111590117970"
  80 "/" "80102969313810111590117970"
  </code></pre>
  
  <p>With regards to @Tomalak: yeah, it was a typo. Sadly it was a typo in both my code here and in the real darn script. ...sigh... Thanks for the catch, though, that seems to have done a lot to help out.</p>
  
  <p>...how embarrassing. =)</p>