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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:00:59+00:00 2026-05-24T12:00:59+00:00

I ma using Javascript function to select menu items: function selectActiveMenuItem() { var path

  • 0

I ma using Javascript function to select menu items:

function selectActiveMenuItem() {
        var path = location.pathname + location.search + location.hash;
        var links = null;

        links = $("a[href='" + path + "']");

        links.parents("li").each(function () {
            $(this).addClass('current').closest('li').addClass('current');
        });
    }

It is working strange – it doesn’t work from the start when homepage is loaded. Homepage link in menu is not selected. I have to click on menu item (homepage or some other) and then it load page once again and right menu item is selected.

Previously I was using only: var path = location.pathname; without location.search and then it was working fine from the begining. But now my links are more complicated – they look for example like that: http://localhost//MainApp/User/Order.aspx?id=949abc91-a644-4a02-aebf-96da3ac7d8e1&type=NMO and other one is http://localhost//MainApp/User/Order.aspx?id=949abc91-a644-4a02-aebf-96da3ac7d8e1&type=MO. So I have to use location.pathname + location.search to make my function work.

Also I tried using var path = location.href.replace(/^.*\/\/[^\/]+/, ''); but the effect was the same as with var path = location.pathname + location.search;– homepage was not selected in menu when page loaded.

The question: How to make homepage selected in menu when page is loaded?

  • 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-24T12:01:02+00:00Added an answer on May 24, 2026 at 12:01 pm

    I had to add checking home link. Now function works and it looks like that:

    function selectActiveMenuItem() {
            var path = location.pathname + location.search + location.hash;
            var createhomelink = null;
            var homepath = null;
            var links = null;
            createhomelink = path + "&from=user";
            homepath = document.getElementById("home").href.replace(/^.*\/\/[^\/]+/, '');
    
            if (createhomelink == homepath) {
                path = createhomelink;
            }
    
            links = $("a[href='" + path + "']");
    
            links.parents("li").each(function () {
                $(this).addClass('current').closest('li').addClass('current');
            });
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create a <select> menu using Javascript then attach it to the page. But
I have a dynamically created select option using a javascript function. the select object
I am using JavaScript, jQuery and PHP. How do I limit the JavaScript function
How do you trigger a javascript function using actionscript in flash? The goal is
I'm using the following code to override a JavaScript function named dismissRelatedLookupPopup(). In Firefox,
I am using jQuery. I call a JavaScript function with next html: <li><span><a href=javascript:uncheckEl('tagVO-$id')>$tagname</a></span></li>
Without using a WebBrowser control, how could I execute a JavaScript function, that is
Is there a way to reload an entire frameset using Javascript onload() event? function
Is it possible to launch a new window in JavaScript using the window.Open function,
I am using jQuery and JavaScript, I need to call the jQuery function inside

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.