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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:17:23+00:00 2026-05-27T14:17:23+00:00

The markup below is an example of a dynamically generated menu that is styled

  • 0

The markup below is an example of a dynamically generated menu that is styled with css as a flyout. I’m just trying to add arrows to show where menus have child menus.

Is it possible, via jQuery, to add a class (“hasChild top”) to the top level elements that have submenus and a class (“hasChild sub”) to the lower level elements that have children?

<ul id="menu-site-menu">
    <li"><a href="#">About Us</a>
        <ul class="sub-menu">
            <li><a href="#">Our Charity Partners</a></li>
            <li><a href="#">Privacy Policy</a></li>
        </ul>
    </li>
    <li><a href="#">Buy Apparel</a>
        <ul class="sub-menu">
            <li><a href="#">Benevolent Elephant</a>
                <ul class="sub-menu">
                    <li><a href="#">Benevolent Elephant Short Sleeve</a></li>
                    <li><a href="#">Benevolent Elephant Long Sleeve</a></li>
                </ul>
            </li>
            <li><a href="#">Eagle-Spirit</a>
                <ul class="sub-menu">
                    <li><a href="#">Eagle-Spirit Short Sleeve</a></li>
                    <li><a href="#">Eagle-Spirit Long Sleeve T-Shirts</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li><a href="#">Customer Service</a></li>
    <li><a href="#">Contact Us</a></li>
</ul>

So. in this example, the jQuery would add the “hasChild top” class to “About Us” and “Buy Apparel”

It would add the “hasChild sub” class to “Benevolent Elephant” and “Eagle Spirit”

  • 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-27T14:17:24+00:00Added an answer on May 27, 2026 at 2:17 pm
    var topLevel = $("ul.nav.menu > li").has("ul");
    topLevel.addClass("hasChild top");
    topLevel.find("li").has("ul").addClass("hasChild sub");
    

    That is, find the li elements that are direct descendants of the top ul, then use .has() to narrow it down to only those that contain a child ul. Give them the “hasChild top” classes. Then, within those top level ones use .find() in combination with .has() to get all lower level menus (no matter how deeply nested) and give them the “hasChild sub” classes.

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

Sidebar

Related Questions

I have the below markup that cannot be changed: <div>Some data</div> <span>More data</span> <a>Link
I have some markup for a popup menu that works in firefox but not
I'm trying to understand what does the markup extension for the x:Key attribute below
I am working on a nav menu the markup structure is below, the span
In below markup, i want to find tag and want to add a common
The markup below is used for my jQuery carousel widget. The first div serves
Thanks for reading this. I have markup similar to what is below. Using the
I have a question regarding image alignment with CSS. For example I have created
I am trying to create a table in an XHTML document shown below (only
I'm trying to add a class to the first td inside a tr within

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.