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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:05:13+00:00 2026-05-20T13:05:13+00:00

This could be the easiest of a problem, but sometimes my dumbness knows no

  • 0

This could be the easiest of a problem, but sometimes my dumbness knows no bounds.

I am trying to create a simple navigation menu. On clicking a link in the navigation menu, it should turn into some different layout and stay like this. I am using this code of jquery,

$(function()
{

    $(".top a").click(function()
    {
        $(this).parent().addClass('active').siblings().removeClass('active');
    };

});

and here is the menu,

<ul class="top">

<li><a href="http://example.com/index.php" class="home"></a></li>

<li><a href="http://example.com/page.php?id=1" class="charter"></a></li>

<li><a href="http://example.com/about_us.php" class="about"></a></li>

<li><a href="http://example.com/policy.php" class="policy"></a></li>

<li><a href="http://example.com/page.php?id=4" class="code"></a></li>

<li><a href="http://example.com/humanitarian.php" class="human"></a></li>

</ul>

I assign class active to li tag whenever someone clicks on any link. But the class is lost on page load. Can someone suggest me how to keep the active class there and keep the link active after the page load. There seems to be something i am missing.

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-20T13:05:14+00:00Added an answer on May 20, 2026 at 1:05 pm

    JavaScript changes to the page do not persist from page to page. Instead you could try something like this:

    $(function () {
        $('.top a').each(function () {
            if (this.href == window.location.href) {
                $(this).addClass('active');
                return false;
            }
        });
    });
    

    The above code will go through your navigation and add active to the first anchor matching the window’s location.

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

Sidebar

Related Questions

this is prob pretty easy but if someone could explain the easiest way to
This could be a very basic Javascript I know but I just can't get
This could save me so much time. Sometimes I find myself writing things like
This could be an amazingly dumb question, but .... I don't think a standard
I think this could be a very easy question for you. But I have
I suppose this could apply to any dynamic language, but the one I'm using
I need to create a scrolling grid of buttons. The easiest way I could
This could quite possibly be the dumbest question ever asked. Our client wants us
This could be considered a duplicate question, as a similar one has already been
I know this could be done manually with some hardcoded Linq Joins. However, I

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.