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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:22:17+00:00 2026-05-29T10:22:17+00:00

I feel like this should be an easy task, but I am having problems.

  • 0

I feel like this should be an easy task, but I am having problems. I have a drop down menu that is wrapped in an unordered list (generated by an asp.net menu control) and I am trying to add extra highlighting to a selected link’s parent link via jquery. Here is the generated HTML:

<div id="MainMenu" class="mainMenuControl">
        <ul class="level1 static" role="menubar">
            <li class="static" role="menuitem"><a class="level1 static selected" href="/default.aspx">Home</a>
            </li>
            <li class="has-popup static" aria-haspopup="MainMenu:submenu:3" role="menuitem"><a
                class="level2 static" href="/store/prodcut.aspx">Product 1</a>
                <ul id="MainMenu:submenu:3" class="level3 dynamic">
                    <li class="dynamic" role="menuitem"><a class="level3 dynamic" href="/store/product/category1.aspx">
                        Category 1</a> </li>
                    <li class="dynamic" role="menuitem"><a class="level3 dynamic" href="/store/product/category2.aspx">
                        Category 2</a> </li>
                </ul>
            </li>
            <li class="has-popup static" aria-haspopup="MainMenu:submenu:10" role="menuitem"><a
                class="level2 static" href="/store/paymentoptions.aspx">Ministries</a>
                <ul id="MainMenu:submenu:10" class="level3 dynamic">
                    <li class="dynamic" role="menuitem"><a class="level3 dynamic" href="/store/paymentoptions/option1.aspx">
                        Option 1</a> </li>
                    <li class="dynamic" role="menuitem"><a class="level3 dynamic" href="/store/paymentoptions/option2.aspx">
                        Option 2</a> </li>
                </ul>
            </li>
        </ul>
    </div>

So, whatever page the current user is on, the corresponding menu link will have the class ‘selected.’ But, if they are on a sub page of one of the main menu choices, I would like the link in the drop down menu as well as it’s parent link to both have the ‘selected’ class.

I was attempting to add classes to the links based on parent/child url paths but I’m running into problems because I am using url rewriting in asp.net so that any trailing slashes, default documents (index.html, default.aspx) or url endings (.html, .aspx, etc) are removed.

I tried this, but, as I said, I can’t get it to work:

$('.mainMenuControl ul a').each(function () {
            if ($(this).attr('href') == window.location.pathname) {
                $(this).addClass('selected');
                if ($(this).parent('li').parents('.mainMenuControl ul.level1 li').length) {
                    $(this).parent('li').parents('.mainMenuControl ul.level1 li').find('a.static').addClass('selected');
                }
            }
        });

Any suggestions would be appreciated, thanks!

  • 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-29T10:22:18+00:00Added an answer on May 29, 2026 at 10:22 am

    Why do it in jQuery. If your using a master page you can create a label called lblMenu.

    So like…

    <div id="MainMenu" class="mainMenuControl">
      <asp:labelControl text = ""/>
    </div>
    

    Then create a class that accepts overides of the names of the items you want selected.
    Build up the HTML for your menu in this class and the options passed to it will have selected against them.

    public string BuildMenu(string selected1, string Selected2)
    StringBuilder sbMenu = new StringBuilder();
    
    sbMenu.Append("<ul class="level1 static" role="menubar">");
    sbMenu.Append .......
    
    return sbMenu.ToString().replace(selected1, selected2);
    

    On your content page_load events put something like..

    lblMenu.Text = className("<a class=""level1 static""","<a class="level1 static selected"");  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Feel like this should be something easy that I'm missing. I have a table
I feel like this should be an easy thing to figure out, but I'm
I feel like this should be an easy question, but I can't get it
I feel like this should be an easy question but I can't seem to
I feel like this should be easy, but i am struggling to return the
I feel like this should be easy, but it seems to be stumping me.
I feel like this should be easy, but google is totally failing me at
I feel like this should be a no brainer, but clearly I'm missing something...
I feel like this should be obvious to me, but for some reason I
I feel like this is something I should already know, but I'm just not

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.