title: JQuery gather Sum of values inside each nested section
body: <p>I am creating a task list with Parent and Child tasks. They are laid out in an ordered list and are nested many levels deep, so a parent task can have child tasks and parent tasks inside as well. </p>
  
  <p>Example:</p>
  
  <pre><code>    &lt;div class="item-list"&gt;
      &lt;ol&gt;
       &lt;li class="parent"&gt;
          &lt;div class="title"&gt;Im a task&lt;/div&gt;
          &lt;div class="totalhours"&gt;total child hours here please&lt;/div&gt;
          &lt;ol&gt;
            &lt;li&gt;
              &lt;div class="title"&gt;Im a task&lt;/div&gt;
              &lt;div class="hours"&gt;5&lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
              &lt;div class="title"&gt;Im a task&lt;/div&gt;
              &lt;div class="hours"&gt;10&lt;/div&gt;
            &lt;/li&gt;
            &lt;li class="parent"&gt;
             &lt;div class="title"&gt;Im a task&lt;/div&gt;
             &lt;div class="totalhours"&gt;total child hours here please&lt;/div&gt;
             &lt;ol&gt;
               &lt;li&gt;
                 &lt;div class="title"&gt;Im a task&lt;/div&gt;
                 &lt;div class="hours"&gt;5&lt;/div&gt;
               &lt;/li&gt;
               &lt;li&gt;
                 &lt;div class="title"&gt;Im a task&lt;/div&gt;
                 &lt;div class="hours"&gt;10&lt;/div&gt;
               &lt;/li&gt;
            &lt;/ol&gt;
           &lt;/li&gt;
          &lt;/ol&gt;
       &lt;/li&gt;
       &lt;li&gt;Another task thats not a parent on this level&lt;/li&gt;
      &lt;/ol&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>So each level I would like to have a total of all nested items. So the very top Parent Task includes the hours of ALL NESTED hours div and then if you drill down it each nested parent does the same for all its nested hours and so on. </p>
  
  <p>This is what I am using at the moment and its just calculating every single hour div instead of only nested and placing the same number everywhere. </p>
  
  <pre><code>    var totalest = $('li.parent .totalhours');
  
      var sum = 0;
  
      $("li .hours").each(function() {
          var val = $.trim( $(this).text() );
  
          if ( val ) {
              val = parseFloat( val.replace( /^\$/, "" ) );
  
              sum += !isNaN( val ) ? val : 0;
          }
  
          totalest.html(sum); 
      });
  </code></pre>
  
  <p>I'm hoping for this result</p>
  
  <ul>
  <li>I'm a Parent task   30 hours
  <ul>
  <li>Im a task  5 hours</li>
  <li>Im a task 10 hours</li>
  <li>Im a Parent task 15 hours
  <ul>
  <li>Im a task 5 hours</li>
  <li>Im a task 10 hours</li>
  </ul></li>
  </ul></li>
  <li>I'm another Parent task   20 hours
  <ul>
  <li>Im a task 5 hours</li>
  <li>Im a task 5 hours</li>
  <li>Im a Parent task 10 hours
  <ul>
  <li>Im a task 5 hours</li>
  <li>Im a task 5 hours</li>
  </ul></li>
  </ul></li>
  </ul>