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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:51:22+00:00 2026-05-13T14:51:22+00:00

I need to highlight the current page in my left nav. The nav has

  • 0

I need to highlight the current page in my left nav.

The nav has to be loaded externally via an .shtml include:

<!--#include file="leftnav-menu.inc"-->

My urls take the form of:

http://www.xxx.com/mission-critical.shtml

but sometimes just:

http://www.xxx.com/energy.shtml (eg one word no hyphen)

My nav lists it as ‘Mission critical’

How can I highlight the ul li with “class=selected”? I’ve seen something like this:

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

Can’t quite get my head around the string splitting etc…

Sample nav bar:

<ul>
<li><a href="corporate-responsibility.shtml">Corporate responsibility</a></li>
<li><a href="overview.shtml">Overview</a></li>
<li><a href="governance.shtml">Governance</a></li>
<li><a href="our-approach.shtml">Our approach</a></li>
</ul>
  • 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-13T14:51:22+00:00Added an answer on May 13, 2026 at 2:51 pm

    Okay, the jQuery syntax was slightly wrong. This should work:

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

    Also, make sure the leftmenuNav is right (your code above doesn’t show it)

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

Sidebar

Related Questions

i have a menu, and i need the link for the current page i
I am working on a page where I need to highlight different events in
I have a single page website which has a fixed floating nav. I want
I need to highlight, case insensitively, given keywords in a JavaScript string. For example:
I need to highlight changes(diff) between 2 database text fields in a asp.net application.
I basically need to highlight a particular word in a block of text. For
I'm programming an application in Struts and I need to highlight some reminders in
I'm working on an asp.net application which uses Lucene.net I need to highlight the
I have a regular texbox control. I need to highlight some words with a
Need help. It may be weird. First activity has listview(like lazyadapter) once i click

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.