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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:55:45+00:00 2026-05-31T10:55:45+00:00

Okay, So what I am trying to accomplish is having the navigation updated with

  • 0

Okay,

So what I am trying to accomplish is having the navigation updated with the “selected” class signifying the page the current end-user is on.

I have tried a multitude of things. But, nothing seems to be working. Here is my code:

The jQuery:

jQuery(function () {
    var path = location.pathname.substring(1);
    if (path)
        jQuery('.navigation ul li a[href$="' + path + '"]').attr('class', 'selected');
});

The HTML:

<div class="navigation">
    <ul>
        <li><a href="index.html">HOME</a></li>
        <li><a href="team.html">TEAM</a></li>
        <li><a href="about.html">ABOUT</a></li>
        <li><a href="services.html">SERVICES</a></li>
        <li><a href="portfolio.html">PORTFOLIO</a></li>
        <li><a href="contact.html">CONTACT</a></li>
    </ul>
    <div class="clear"></div>
</div>

The CSS:

.navigation li a.selected {
    background: url(../images/navigation-background-active.png) repeat-x;
    text-decoration: none;
}

If you are confused of what I am asking for… You can view this link:
http://docs.jquery.com/Tutorials:Auto-Selecting_Navigation

Thank you so much!

  • 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-31T10:55:47+00:00Added an answer on May 31, 2026 at 10:55 am

    Edit: I looked at your website and the value of path is portfolio/newish/index.html

    Probably you should substring based on lastIndexOf /. Try below,

    jQuery(function () {
        var path = location.pathname; //return /portfolio/newish/index.html
        path = path.substring(path.lastIndexOf('/') + 1); //will return index.html
    
        if (path)
            jQuery('.navigation ul li a[href$="' + path + '"]').addClass('selected');
    });
    

    Your code looks fine as is, but I think you should use .addClass to add a class to an element. Try below,

    jQuery('.navigation ul li a[href$="' + path + '"]').addClass('selected');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I been trying to work this out but unable too. I have a
okay i have been trying to understand this for hours i am learning VB
Okay here is what I'm trying to do: I have a model object that
Okay, what I'm trying to accomplish is a simple tool tip that, when you
Okay so here is what I'm trying to accomplish. First of all below table
Okay so i'm trying to convert a couple things. So i have already converted
Okay I'm trying to have a custom keypad pop-up when I want to enter
This is going to be long... Okay, so what I'm trying to accomplish is
Okay i'm trying to understand WPF and the popular MVVM Pattern. Now i have
Okay I have been trying to get this to work for some time now.

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.