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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:32:03+00:00 2026-05-19T15:32:03+00:00

I have a menu and pretty much each item in it has a submenu.

  • 0

I have a menu and pretty much each item in it has a submenu. the menu system is structured like this

<div id="leftNav">
    <ul class="level1">
        <li><a href="#">Link1</a>
            <ul class="level2" id="submenu01">
                <li class="deptName"><a href="#">Link1</a></li>
                <li><a href="#">Link1.1</a></li>
                <li><a href="#">Link1.2</a></li>
                <li><a href="#">Link1.3</a></li>
            </ul>
        </li>
        <li><a href="#">Link2</a>
            <ul class="level2" id="submenu02">
                <li class="deptName"><a href="#">Link2</a></li>
                <li><a href="#">Link2.1</a></li>
                <li><a href="#">Link2.2</a></li>
                <li><a href="#">Link2.3</a></li>
            </ul>
        </li>
    </ul>
</div>

where .level2 is the submenu. I need to add a class to each anchor in the submenu, except for the anchor in the li with the deptName class. this is easy enough, but, i need the class to be “levelTwoLinkXX” where “XX” is the 01 for the first, 02 for the second and so on. Then this needs to happen for each level2 starting back at levelTwoLink01 for the first link not in the deptName class.

The javascript I came up with is:

$(function(){
    $('.level2 > li:not('.deptName') > a').each(function(){
        $(this).addClass('levelTwoLink0' + (index+1));
    });
});

the problem is that it starts at 01 and by the time it assigns the class to #submenu02 the index is at 4. How would i go about getting it to restart for each new submenuXX?

  • 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-19T15:32:04+00:00Added an answer on May 19, 2026 at 3:32 pm
    $('ul.level2').each(function() {
        $(this).find('li').not('.deptName').each(function(i) {
            $(this).find('a').addClass('levelTwoLink0' + (i+1));
        });
    });
    

    Demo: http://www.jsfiddle.net/DAunT/3/

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

Sidebar

Related Questions

I have an application which resides in menu bar, pretty much like this one
In pretty much all applications that have a menu bar, some of the items
I have a menu div that I want to slide down so it's always
I have a vertical menu in my system which is basically made of HTML
I have a jquery menu that has so many entries that it extends further
Well, the title is pretty much the whole question. I'd like to be able
I'm pretty much at my wits end with this issue. I've been searching for
I have read pretty much EVERY blog post, article and help document published regarding
I have created a menu and submenu bar for my web app. Now with
I have changed my app to use MVC and it has gotten pretty slow.

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.