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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:02:45+00:00 2026-05-20T22:02:45+00:00

I am still fairly new to Stackoverflow, so forgive me if I am doing

  • 0

I am still fairly new to Stackoverflow, so forgive me if I am doing this wrong. This question pertains to another question I asked a couple of weeks ago, which was solved at jQuery toggle() with dynamic div ID's

I recommend you check the link I posted, so you can know what I am talking about.

So I now have my list of items being generated, I have switched out the “button” code and replaced it so each generated item is a “li” – however, I now have a list of items in my menu that have no order to them. I need to designate some items as top level items, and have other items as sub-items on a drop down menu.

I was thinking that I could perhaps tweak my classes so that when the buttons are generated, top level items have a class and sub-level items have a class, something along the lines of:

<div class="category-1-top-level-item">Main Item</div>
<div class="category-1-sub-item">Sub Item</div>
<div class="category-1-sub-item">Sub Item</div>

<div class="category-2-top-level-item">Main Item</div>
<div class="category-2-sub-item">Sub Item</div>
<div class="category-2-sub-item">Sub Item</div>

Then, perhaps, jQuery could be used to detect the top level item “category-1” and any sub items marked “category-1-sub-item” and then output a properly formatted list:

<ul>
    <li>Top Level Item
        <ul>
            <li>Sub Item</li>
            <li>Sub Item</li>
        <ul>
    </li>
</ul>

Then, of course, that list could be styled with CSS to make a nice drop down menu for sub-items and such.

I don’t know if this would work as a solution or not (if it does then great), but I have been struggling with the code needed to get this working properly.

If someone could help, it would be appreciated so much!

  • 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-05-20T22:02:46+00:00Added an answer on May 20, 2026 at 10:02 pm

    Though verbose, this seems to do what you’re after:

    var topLevel = $('<ul />');
    var subMenus = {};
    
    function getId(el){
        return el.attr('class').split('-')[1];
    }
    
    $('div[class^="category-"][class$="-top-level-item"]').each(function(){
        var topLevelDiv = $(this);
        var id = getId(topLevelDiv);
        var subItems = $('<ul />');
        var li = $('<li />').text(topLevelDiv.text())
            .append(subItems).appendTo(topLevel);
        subMenus[id] = subItems;
    });
    
    $('div[class^="category-"][class$="-sub-item"]').each(function(){
        var subLevelDiv = $(this);
        var id = getId(subLevelDiv);
        var li = $('<li />').text(subLevelDiv.text())
            .appendTo(subMenus[id]);
    });
    
    
    topLevel.appendTo('body');
    

    Working example: http://jsfiddle.net/kobi/UuaSA/

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

Sidebar

Related Questions

This is a bit of noob question - I'm still fairly new to C#
I may be asking the wrong question but I am still fairly new to
I'm still fairly new to symfony, so my apologies if this is a stupid
Notes: I'm still fairly new to php This login form seems to work perfectly
So I am still fairly new to all of this, that is coding, OS
I'm still fairly new to Java and have a question in regards to JTable
Please forgive me, I am still fairly new to cakephp and in the process
I am still fairly new to C# and I have a question regarding attributes.
You'll have to forgive me because i'm still fairly new to Obj-C but i'm
I'm still fairly new to Obj-C and the idea of blocks. I read this

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.