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 8391567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:17:52+00:00 2026-06-09T19:17:52+00:00

How do you loop through the results from a children() or each() call in

  • 0

How do you loop through the results from a children() or each() call in jQuery when you want to work with some cumulative result? For example sum up numbers in checkboxes and change a class if they get over 100%. All the example seem to only perform logic that is independent for each iteration.

I’m looking for the javascript/jquery equiv of this c#

var x = new List<int> { 1, 2, 3 };
Console.WriteLine(x.All(y => y > 0));

This is what I have now, but it seems like there should be something cleaner.

var count = 0;
$(this).parent().children().each(
    function () {
        if ($(this).hasClass("selected")) {
            count++;
        }
    }
);

if ($(this).parent().children().length == count) {
    $(this).parent().parent().toggleClass("selected");
}
else {
    $(this).parent().parent().removeClass("selected");
}
  • 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-09T19:17:53+00:00Added an answer on June 9, 2026 at 7:17 pm

    Aside from the obvious iterate and sum approach, you can use the newer javascript iteration functions. Assuming you want so sum some numbers:

    var sum = objects
        //convert to jquery selection of numbers
        .map(function() {return +$(this).val(); })
        //convert to javascript array
        .get() 
        //add together
        .reduce(function(a, b) { return a + b; });
    

    For your example:

    var checkboxes = $(this).parent().children()
    var allSelected = checkboxes.map(function () {
        return $(this).hasClass("selected");
    }).get().every(function(x) { return x; });
    

    You can go one stage better by extending jQuery

    $.fn.every = function(f) {
        return [].every.call(this, function(x) {
            return f.call(x);
        });
    }
    

    Leaving you with:

    var checkboxes = $(this).parent().children()
    var allSelected = checkboxes.every(function() {
        return $(this).hasClass("selected");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a way to loop through each of the results from
I'm trying to loop through the results from the Last.fm API but it's not
I'm trying to loop through a list of results from MySQL and display all
I've got some code to try and loop through LINQ results, but it doesn't
setup Controller -> Action Index results = Model.all (SQL Call) View Loop through and
I am trying to loop through a number of results from a form, but
If I'm looping through results from a JSON call, how do I know if
How PreparedStatement.executeQuery works? Does it fetch results from database and I loop through them?
How to loop through a select statement results to have a formatted text? for
I have a while loop that loops through 3 results and echo's these out

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.