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

  • Home
  • SEARCH
  • 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 7823623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:18:51+00:00 2026-06-02T08:18:51+00:00

A container div.example can have different 1st-level child elements ( section , div ,

  • 0

A container div.example can have different 1st-level child elements (section, div, ul, nav, …). Quantity and type of those elements can vary.

I have to find the type (e.g. div) of the direct child that occurs the most.
What is a simple jQuery or JavaScript solution?

jQuery 1.7.1 is available, although it should work in IE < 9 (array.filter) as well.

Edit: Thank you @Jasper, @Vega and @Robin Maben 🙂

  • 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-02T08:18:53+00:00Added an answer on June 2, 2026 at 8:18 am

    Iterate through the children using .children() and log the number of element.tagNames you find:

    //create object to store data
    var tags = {};
    
    //iterate through the children
    $.each($('#parent').children(), function () {
    
        //get the type of tag we are looking-at
        var name = this.tagName.toLowerCase();
    
        //if we haven't logged this type of tag yet, initialize it in the `tags` object
        if (typeof tags[name] == 'undefined') {
            tags[name] = 0;
        }
    
        //and increment the count for this tag
        tags[name]++;
    });
    

    Now the tags object holds the number of each type of tag that occurred as a child of the #parent element.

    Here is a demo: http://jsfiddle.net/ZRjtp/ (watch your console for the object)

    Then to find the tag that occurred the most you could do this:

    var most_used = {
            count : 0,
            tag   : ''
        };
    
    $.each(tags, function (key, val) {
        if (val > most_used.count) {
            most_used.count = val;
            most_used.tag   = key;
        }
    });
    

    The most_used object now holds the tag used the most and how many times it was used.

    Here is a demo: http://jsfiddle.net/ZRjtp/1/

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

Sidebar

Related Questions

I have 2 html elements, 1. <div class=drag>..example.jpg..</div> contains images that can be dragged/cloned/dropped.
I have a couple of div elements contained in one container div , and
I have a container with different draggable -elements and there is a list of
I want to have an inner div that sites inside different sized container divs,
I'm trying to move child div elements between two different parent divs using jQuery
I have a base.html template that contains a list of links. Example: <div id=sidebar1>
I have a container DIV which contains several block-DIVS. Every block-DIV contains SPAN items
i have a container div which is position:relative and the squares are position:absolute because
I have a container div with the following CSS: #container { position:relative; overflow:hidden; width:200px;
I have a container (div) with a background image. In this div there is

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.