Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:40:28+00:00 2026-06-18T14:40:28+00:00

I am creating a task list with Parent and Child tasks. They are laid

  • 0

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.

Example:

    <div class="item-list">
    <ol>
     <li class="parent">
        <div class="title">Im a task</div>
        <div class="totalhours">total child hours here please</div>
        <ol>
          <li>
            <div class="title">Im a task</div>
            <div class="hours">5</div>
          </li>
          <li>
            <div class="title">Im a task</div>
            <div class="hours">10</div>
          </li>
          <li class="parent">
           <div class="title">Im a task</div>
           <div class="totalhours">total child hours here please</div>
           <ol>
             <li>
               <div class="title">Im a task</div>
               <div class="hours">5</div>
             </li>
             <li>
               <div class="title">Im a task</div>
               <div class="hours">10</div>
             </li>
          </ol>
         </li>
        </ol>
     </li>
     <li>Another task thats not a parent on this level</li>
    </ol>
    </div>

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.

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.

    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); 
    });

I’m hoping for this result

  • I’m a Parent task 30 hours
    • Im a task 5 hours
    • Im a task 10 hours
    • Im a Parent task 15 hours
      • Im a task 5 hours
      • Im a task 10 hours
  • I’m another Parent task 20 hours
    • Im a task 5 hours
    • Im a task 5 hours
    • Im a Parent task 10 hours
      • Im a task 5 hours
      • Im a task 5 hours
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:40:30+00:00Added an answer on June 18, 2026 at 2:40 pm

    Loop through each parent and add hours only to that parent.

    $(".parent").each(function() {
      var sum = 0;
      $(".hours", this).each(function() {
        var val = $.trim( $(this).text() );
    
        if ( val ) {
          val = parseFloat( val.replace( /^\$/, "" ) );
    
          sum += !isNaN( val ) ? val : 0;
        }
    
      });
      $(this).find('.totalhours').html(sum); 
    });
    

    http://jsfiddle.net/qqhD6/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a list of class Task in a way such as this. List<Task>
I have written the code for creating a list out of some arrays shown
I am creating a task list with number of hours worked to be entered
My application is an apporval system.I am creating data view from a task list
I have a Task factory thats kicking off many tasks, sometimes over 1000. I
I am creating, say, 15 Callable tasks, and submitting them: List<Future<MyResult>> futures = new
I'm creating a todo list app. User has_many tasks through categories. I'm creating new
I'm creating a new task in Asana - Task Management for Teams via the
I have the task of creating implementations for a large number of metric data
I'm trying to accomplish a simple task of creating a database with 2 tables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.