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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:41:26+00:00 2026-06-12T09:41:26+00:00

this is in reference to this other thread as well: jQuery – If URL

  • 0

this is in reference to this other thread as well: jQuery – If URL matches href then move LI to top of UL?

Jquery code:

//set var to current url
var url = window.location.toString();

//if url matches li's anchor then bring it to the top of the list
$('.nav li a').each(function(){
   var myHref= $(this).attr('href');
   if( url == myHref) {
        $(this).closest("li").prependTo(".nav");
   }
});

The HTML is just from a WordPress Navigation so something like:

<navrole="navigation">
  <ul>
    <li>
      <a href="">

The navigation points to categories, and the url matches the href’s fine and the code works. But, I cannot figure out how to get the code to also fire when I am in a child page of a category, for example when the url is:

domain.com/category-name/child-page

If I can get the Jquery to only detect the first pathname past the domain, then I will be golden. Anything past the first pathname could be omitted or setup as a wild card or something.

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-12T09:41:27+00:00Added an answer on June 12, 2026 at 9:41 am

    You can try using attribute contains selector:

    var dom = document.domain;
    var f = location.pathname.split('/')[1]; 
    var url = dom + "/" + f;
    
    $('.nav li a[href*="'+url+'"]').closest("li").prependTo(".nav");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I do this without reference to the object in the constructor? In other
I have referenced this previous question as well as other sources, but cannot get
ok I am well aware there are many other questions about this, but I
We have been trying to analyse this exception: Message: Error: Object reference not set
I'm not interested in call or apply to change the this reference. Just for
I have a large non static JAVA function, which uses this reference at several
when i search for open source for domain checker, i got this reference http://www.codeproject.com/KB/aspnet/DataScraping.aspx
**c:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(0,0): warning MSB3245: Could not resolve this reference. Could not locate the assembly System.Web.Mvc,
Goetz's Java Concurrency in Practice , page 41, mentions how this reference can escape
Reference: This is a self-answered question. It was meant to share the knowledge, Q&A

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.