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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:05:48+00:00 2026-06-03T20:05:48+00:00

UPDATE: Tried using regex for the url and it works: var url = window.location.pathname,

  • 0

UPDATE:

Tried using regex for the url and it works:

var url = window.location.pathname, 
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");

$("#accordion a").each(function()
{
    if(urlRegExp.test(this.href.replace(/\/$/,'')))
    {
        $(this).addClass("active-sidebar-link");
    }
});

I’m using the jQuery UI Accordion Widget to build a sidebar navigation menu for my website.
http://jqueryui.com/demos/accordion/

I have the following code:

// create accordion
$( "#accordion" ).accordion(
{
    header: '> li, h3:not(> li > ul)',
    collapsible: true,
    autoHeight: false,
    navigation:true 
});

// Add active class to active sidebar links
$("#accordion a").each(function() 
{
    if (this.href == window.location || this.href == document.location.protocol + "//" + window.location.hostname + window.location.pathname)
    {
        $(this).addClass("active-sidebar-link");
    }
});

The accordion works and the “navigation: true” option also works (http://jqueryui.com/demos/accordion/#option-navigation), it opens the appropriate accordion “drawer” based on the link you’re visiting.

However the active class is not being added to the current link.

Any ideas?

  • 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-06-03T20:05:49+00:00Added an answer on June 3, 2026 at 8:05 pm

    I would do a search function on the href value. If you have links to multiple pages, then you could take the code further to include window.location.pathname, but here’s a good start on searching for the domain name:

    $("#accordion a").each(function() 
    {
        if (this.href.search(window.location.hostname) != -1)
        {
            $(this).addClass("active-sidebar-link");
        }
    });​
    

    Or, as I said in my comment above, you may want to use a regex instead.

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

Sidebar

Related Questions

UPDATE I tried using the internal wordpress rewrite. What I have to do is
One update: I tried using the SummaryRow on the datagrid for its basic functionalities
I'm using Xcode 4.3.2 and it tried to install an update to the command
I want to update two fields using counterCache in CakePHP 2.x. I tried this
UPDATED SCRIPT I'M USING THAT CAUSES LOCKUP...I tried replacing the (Replace:=wdReplaceOne) with (Replace:=wdReplaceAll), but
I tried using bundle update for a Rails 3.0.0 project I created, expecting all
UPDATE: I tried implementing the method specified by Peter and am getting incorrect shadowing.
Is it possible to update first row and with WHERE clause. I Tried: UPDATE
This question reflects my issue. How to do this in SQLite? I've tried UPDATE
I tried to update some part of a matrix, I got the following error

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.