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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:46:19+00:00 2026-06-11T12:46:19+00:00

I need help working with a large list of sibling elements with different class

  • 0

I need help working with a large list of sibling elements with different class names.

  1. Getting the amount of elements with the same class name and putting them in an array
  2. Finding first element in that class group (this can be number or name).
  3. Statement that runs a function: if element = first element of group do console.log("first element");

Here’s an example of the first 3 classes but this will go from groupA to Groupz

<div class = 'slider'>
    <div class = 'item1 groupA'> <!-- Start Group A -->
        <img  src='xyz'  />
    </div>
    <div class = 'item1 groupA'>
        <img  src='xyz'  />
    </div>                  
    <div class = 'item1 groupA'>
        <img  src='xyz'  />
    </div>                  
    <div class = 'item1 groupA'>
        <img  src='xyz'  />
    </div>
    <div class = 'item1 groupB'> <!-- Start Group B -->
        <img  src='xyz'  />
    </div>
    <div class = 'item1 groupB'>
        <img  src='xyz'  />
    </div>                  
    <div class = 'item1 groupB'>
        <img  src='xyz'  />
    </div>                  
    <div class = 'item1 groupC'> <!-- Start Group C -->
        <img  src='xyz'  />
    </div>          
    <div class = 'item1 groupC'>
        <img  src='xyz'  />
    </div> <!-- All the way to group Z -->
</div>
  • 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-11T12:46:20+00:00Added an answer on June 11, 2026 at 12:46 pm

    Edit: Your requirement is very specific. Below is just a sample to just loop thru all childrens and store the count and first element in the matching count. Let me

    $(function () {
        $.fn.benton = function () {
            //just the immediate childrens
            var $chds = $(this).children();
    
            var lc = {
                firstEl: {},
                classCount: {}
            };
    
            $.each ($chds, function (idx, el) {
                if (el.className) {
                   var tokens = el.className.split(' ');
                   for (var i = 0; i < tokens.length; i++) {
                       if (lc.classCount.hasOwnProperty(tokens[i])) {
                           lc.classCount[tokens[i]] += 1;
                       } else {
                           lc.classCount[tokens[i]] = 1;
                           lc.firstEl[tokens[i]] = $(el);
                       }
                   }
                }
            });
    
            return lc;                   
        };
    
        var stats = $('.slider').benton();
        console.log(stats.classCount['groupA']);
        stats.firstEl['item1'].css({border: '1px solid red', width: 100, height: 10});
    });
    

    DEMO: http://jsfiddle.net/LhwQ4/1/


    I think what you need is to use context of slider to get the child elements.. see below,

    var $slider = $('.slider') 
    

    Now using the $slider context,

    $('.groupA', $slider)
    //Returns Array of jQuery object with elements has class `groupA`
    
    $('.groupA:first', $slider)
    //Returns first element in collection of element with class `groupA`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help getting CommonJS working on Java 7 and Rhino 1.7R3. Rhino 1.7R3
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
Im working on a large project, havent had to do what I need help
I'm working on an offline only help system which requires loading a large amount
I need help working with very big numbers. According to Windows calc, the exponent
All i need help in downloading a file through headers its working fine but
Ok, I need help. This is my first question here. Background: I am working
I am working with an array and need some help. I would like to
I'm working on a web application and need some help with a query. I'm
I need your help to translate a query into pyes. This query is working

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.