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

  • Home
  • SEARCH
  • 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 945685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:47:33+00:00 2026-05-15T22:47:33+00:00

I have a navigation menu within a page on my site, which has JavaScript

  • 0

I have a navigation menu within a page on my site, which has JavaScript applied to it to highlight the currently selected link.

The problem is I have the same menu on my homepage and when I click a link on the homepage, it goes to the intended section, but it doesn’t initially highlight the corresponding link.

For example, on the home page, there is a nav menu with links [1, 2, 3, 4, 5, 6]. Now on the "writing" page within the site, there is also the same nav links [1, 2, 3, etc.]. The links on the "writing" page have javascript applied, so when a link is clicked it will highlight the selected link. But when I click link 1 from the homepage it will go to the link 1 on the "writing" page but the link wouldn’t be highlighted. I would have to click another link and then go back to it to highlight it.

Here is the coding used for the nav menu within the "writing" page:

<div id="article-nav-container">
    
        <ul id="article-nav-pg">
            <li><a href="articles.php?article=article_name1#articles-top">1</a></li>
            <li><a href="articles.php?article=article_name2#articles-top">2</a></li>
            <li><a href="articles.php?article=article_name3#articles-top">3</a></li>
            <li><a href="articles.php?article=article_name4#articles-top">4</a></li>
            <li><a href="articles.php?article=article_name5#articles-top">5</a></li>
            <li><a href="articles.php?article=article_name6#articles-top">6</a></li>
        </ul>
        
        <script type="text/javascript">
                $(document).ready(function() {
            var loc = window.location.href; // The URL of the page we're looking at
            $('#article-nav-pg a').each(function() {
                if (loc.indexOf(this.href) !== -1) { // If the URL contains the href of the anchor
                        $(this).addClass('selected'); // Mark it as selected
                }
            });
        });
        </script>
        
    </div><!-- end articles nav -->

The coding for the homepage nav (no JavaScript) is:

<ul id="article-nav">
        <li><a href="articles.php?article=article_name1">1</a></li>
        <li><a href="articles.php?article=article_name2">2</a></li>
        <li><a href="articles.php?article=article_name3">3</a></li>
        <li><a href="articles.php?article=article_name4">4</a></li>
        <li><a href="articles.php?article=article_name5">5</a></li>
        <li><a href="articles.php?article=article_name6">6</a></li>
    </ul>

I would appreciate any help on how to link the JavaScript effect to the homepage nav menu so that when a link is clicked the corresponding page will load with the link selected. Using the existing JavaScript or any other technique. Hope this wasn’t too confusing.

Here is the link to the site: here

Thanks,

gdinari

  • 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-15T22:47:34+00:00Added an answer on May 15, 2026 at 10:47 pm

    The links on the homepage look like this: articles.php?article=article_name4.

    The links off the homepage look like this:articles.php?article=article_name4#articles-top

    When you click on the first link, it checks to see if that latter URL is a substring of the former URL. It isn’t, so nothing is selected.

    Is #articles-top actually necessary at all?

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

Sidebar

Related Questions

I have an application that has a top level navigation menu which consists of
I have a NAVIGATION MENU, and within this MENU I have selected tags hence
I currently have a navigation-menu: ... <p:menuitem id=id1 value=Page 1 action=home.xhtml?faces-redirect=true actionListener=#{homeBean.someMethod(1)}/> <p:menuitem id=id2
I have a custom navigation menu for my SharePoint intranet web application which is
I have a row of evenly-spaced navigation items, which looks like this: The currently
I have a navigation menu, footer, and a slideshow which use listed style to
I need to have a navigation menu that reflects page changes based on clicks
I have a navigation menu out side ckeditor and i want to navigate within
I have a navigation menu on this site: http://blog.helpcurenow.org/test/redesignMockup/ where I have set the
I have a navigation menu that has links with CSS3 transitions with a speed

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.