JS-powered menu links losing color after being clicked

I have a JavaScript rollover switch issue - when I click on the link, the color should stay orange (#f7931d), but it reverts back to grey. What am I missing in my code?

CSS:

#content-slider {
    padding-top:5px;
    height: 240px;
    width: 359px;
    padding-left: 52px;
    font-family: 'Century Gothic';
    font-size: 11px;
    color: #BBBDC0;
    display:inline-block;
    padding-bottom:25px;
    overflow: hidden;
}

#content-slider-inside {
    list-style: none;
    height: 240px;
    overflow:hidden;
    overflow-y: hidden;
}

    #content-slider-inside li {
        height: 340px;
        width: 359px;
        font-family: 'Century Gothic';
        font-size: 11px;
        color: #BBBDC0;
        display:inline-block;
        padding-bottom:25px;
    }

#navigation {
    font-family: 'Century Gothic';
    font-size: 14px;
    color: #BBBDC0;
    display: inline-block;
    width: 940px;
    height: 18px;
    text-transform: uppercase;
    padding-left: 45px;
    padding-top: 20px;
    padding-bottom:10px;
    overflow: hidden;
    white-space: nowrap;
    text-decoration: none;
}

#navigation li {
    color:#bbbdc0;
    display:inline-block;
    padding:5px;
    text-decoration: none;

}

#navigation li a, #navigation li a:link, #navigation li a:visited {
    color:#bbbdc0;
    display:inline-block;
    text-decoration: none;

}

#navigation li a.selected, #navigation li a.selected:link, #navigation li a.selected:visited, #navigation li a.selected:active {
    color:#f7931d;
    display:inline-block;
    text-decoration: none;
}

#navigation li a:hover, #navigation li a:focus, #navigation li a:active, #navigation li a:focus:active {
    display:inline-block;
    text-decoration: none;
    color:#f7931d;
}

HTML:

<ul id="navigation">
    <li><a href="#overview">overview</a></li>
    <li><a href="#features">features</a></li>
    <li><a href="#resumemanagement">resume management</a></li>
    <li><a href="#financials">financials</a></li>
    <li><a href="#tracking">expense tracking</a></li>
    <li><a href="#search">search</a></li>
</ul>

The remaining code consists of tags and anchors for when the link is clicked.

<div id="content-slider">
    <ul id="content-slider-inside">
        <li id="overview">
            text            
        </li>
        <li id="features">
            text
        </li>
        <li id="resumemanagement">
            text                
        </li>
        <li id="financials">
            text
        </li>
        <li id="tracking">
            text            
        </li>
        <li id="search">
            text            
        </li>
    </ul>
</div>

Answer №1

, it seems like you're inquiring about maintaining highlight on a menu item if it's the current page. I stumbled upon this neat jQuery snippet on Stack Overflow some time ago, although I'm unsure of its proper attribution. If anyone recognizes it, please reach out so I can give credit where it's due!
<script>
    $(document).ready(function(){
        var url = window.location.href.substr(window.location.href.lastIndexOf("/") + 1);
        $('[href$="'+url+'"]').parent().addClass("nav-active"); //swap 'nav-active' with your preferred highlighting class— perhaps an orange shade in this instance.
    });
</script>

In essence, this script scans the browser's URL, and if it matches the end of a menu item's URL, it ensures that it stays highlighted.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hero Sticky Transition with 100vhDivElement

My code is giving me some trouble. I want the div with text to stay at the bottom of the hero section with a transparent background. When that div reaches the top, it should stick with a black background. The issue is that I have set it in the javascript v ...

The styling options for PHP table are limited

I have been assigned a task for homework that involves connecting a MySQL database to our PHP files and displaying the data in an HTML table. Although I have successfully connected to the database, I am facing difficulties styling the table. All other elem ...

I'm looking to optimize my paragraph for small screens by incorporating a Google AdSense banner

I need help adjusting my content with a Google banner for small screens. Here is an example image: Example Image Within the parent div with the class name parent-content, there is a banner div named ad3. Below is the code I have written for screens with ...

Ensure that the user's browser cache is cleared after deploying a new version on Firebase hosting

Utilizing create-react-app for my front end scripts and firebase hosting for deployment has been smooth overall. However, I've encountered an issue where updates to CSS and HTML files don't always reflect on the domain until I manually clear the ...

Ways to retrieve targeted keyframes using JavaScript

Trying to access a scoped "keyframes" named move-left in JavaScript. How can I do this while keeping it scoped? Note that vue-loader will add a random hash to move-left, such as move-left-xxxxxxxxx. <template> <div :style="{animation: animati ...

I am encountering an issue with opening a dropdown select option upon clicking in C# while using Selenium

I am encountering an issue while attempting to open the Register page from my account. The UI developer utilized Bootstrap code, and Bootstrap developers have included a JS function on click. However, when I execute this code, an error is thrown: "OpenQA.S ...

Enhance your HTML audio player with added timeline functionality

I'm currently working on incorporating an HTML audio player into my project. I've managed to get the play/pause functionality to work, but now I'm stuck on adding a timeline feature. Additionally, I'm not sure how to implement the play/ ...

Attempting to align an image in the middle of a webpage using CSS styling

Solving simple CSS problems used to be a breeze for me with just some trial and error. However, I've been struggling all day without any success. At this point, I'm at a loss for what to do. My current challenge is centered around aligning an im ...

Creating a unified border style for both <p> and <ul> tags in HTML5

Is there a way to have both paragraphs and unordered lists contained within the same border? I initially thought I could achieve this by placing the list inside the paragraph tag, but that does not seem to work. Below is a snippet of my external style sh ...

What is the best way to eliminate vertical spacing among li elements in CSS

I am facing a challenge with my HTML code and styling, which is just an example: <div id="mn" style="margin-top:200px;"> <div class="first">1</div> <div class="second">2</div> & ...

What is the best way to position the footer at the bottom of the page without obstructing any content?

I am currently working on a project that utilizes Bootstrap, and I am facing an issue with positioning the footer. Ideally, I want the footer to stay fixed at the bottom of the screen when there is not enough content to fill the page. However, when the con ...

Upon rerender, React fails to refresh the style changes

I am encountering an issue with my React component where the visibility and position can be changed by the user. Currently, the visibility can be toggled by adding or removing a CSS class, while the position is adjusted through a function that updates the ...

What is the best way to ensure that an anchor in a scrolling list adjusts its width based on its children's content?

Check out the setup I have here: http://jsfiddle.net/9F6CF/ In this scenario, there is a list containing anchors within each list item. The UL element has a specific width and an overflow set to auto, causing text in the anchors to scroll horizontally if ...

What is the best way to align text above a wrapper box?

After watching a tutorial on YouTube about creating a simple login form, I decided to customize it with some personal touches. I wanted to include a "Welcome" text above the login form, but when using h1, the text appeared next to the box rather than abov ...

background with alternating stripes to decorate the border of a div

Is it possible to give a striped effect to a div element's border using jQuery? Consider the following code snippet: <style type="text/css"> #panel { padding: 50px text-align: center; background-color: #e5eecc; bord ...

Different Ways Split Button Format Can Vary Based on Web Browser

I am encountering a formatting issue with a jQuery splitbutton on my webpage. In order to adhere to my company's design standards, I am essentially converting a link into a button. The functionality works perfectly fine; however, depending on the brow ...

Looking to replicate a Modal that I designed, but unsure which elements need altering in order to achieve this. I am hoping to create three duplicates of the Modal

This modal is functioning perfectly, and now I want to replicate the same modal three times on a single page. I require three distinct buttons on the same page to trigger these separate modals. At this point, I am unsure which attributes need modification ...

jQuery width property does not seem to be functional on menus that do not contain any dropdown

I am currently working on creating a menu that displays arrows underneath the items when hovered over or when the .active class is added to the menu. Everything is working fine, except for the fact that it only works on menus with drop-downs and the child ...

Following an AJAX request, jQuery.each() does not have access to the newly loaded CSS selectors

Note: While I value the opinions of others, I don't believe this issue is a duplicate based on the provided link. I have searched for a solution but have not found one that addresses my specific problem. Objective: Load HTML content to an element u ...

Strategies for Increasing Index Values in JavaScript

I attempted to modify the data attribute in my code snippet below. After clicking on the square, the data attribute should be incremented. However, it appears that the incrementing is not happening as expected. How can I resolve this issue? Additionall ...