keep the color of the link after clicking until a different link is clicked

At the bottom of every post on my website, there are 3 buttons: "Written By", "Related Post," and "In This Category": SoCatchy!

I'm looking to have each button change color when clicked, and stay that way until another link is clicked.

Here is the code I currently have:

HTML:

<ul class="tabnav-widget ui-tabs-nav">
   <li class="ui-tabs-selected">
      <a class="" href="#tab1-widget">written by</a>
   </li>
   <li>
      <a class="" href="#tab3-widget">Related Posts</a>
   </li>
   <li class="">
      <a class="" href="#tab4-widget">In this Category</a>
   </li>
</ul>

CSS:

.tabnav li a, .tabnav-widget li a{color:@white;}
.tabnav li:active, .tabnav-widget li:active{background:@white;}

In jQuery, I am unsure about the function I need to create in order to achieve my desired result. Any guidance would be appreciated.

Thank you in advance for any assistance provided.

Answer №1

JavaScript makes it achievable.

$(".tabnav-widget li a").click(function(){        
   if(!($(this).hasClass("active"))){
       $(".tabnav-widget li a.active").removeClass("active");
       $(this).addClass("active");
   }       
});

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

Scroll positioning determines the height of an entity

Here's a code snippet I'm working with: HTML: <div id="wrap"> <div id="column"></div> </div> CSS: #wrap { display: block; height: 2000px; width: 400px } #column { display: block; height: 20px; ...

The onmessage event in the websocket client seems to be malfunctioning and is not triggering

In my implementation using node.js, I have set up a websocket server and client. The handshake process between the server and client appears as follows: Request URL: ws://localhost:8015/ Request Method: GET Status Code: 101 Switching Protocols Request ...

How can we create a touch and mouse-friendly horizontal scrolling navigation pattern?

I am trying to implement horizontal scrolling for video testimonials in a single row on a responsive website, but I am encountering an issue. The width of the container class is larger than col-12, which leaves space and causes horizontal scroll on the pag ...

Despite receiving the response, the AJAX GET request is still encountering an error

I'm having an issue with a GET request to fetch JSON from an API for my website. Despite displaying the response correctly in the network tab of the Console and showing a 200 status (images attached), it keeps resulting in an error. I've verified ...

Ways to display dynamic content within a div using Bootstrap's vertical tab through a click event in PHP

I have been working on displaying static content in a div using Bootstrap vertical tabs, similar to this: Link: However, I am facing an issue with showing dynamic content in a div using a Bootstrap vertical tab through a PHP click event. I have been try ...

Effortlessly navigate between Formik Fields with automated tabbing

I have a component that validates a 4 digit phone code. It functions well and has a good appearance. However, I am struggling with the inability to autotab between numbers. Currently, I have to manually navigate to each input field and enter the number. Is ...

query in PHP to display specific data

Seeking guidance for developing a document tracking system using PHP. Struggling with defining the correct title for my project and unable to generate relevant keywords for search queries. The main issue pertains to determining how the system can validat ...

Concealing a column within an Angular Material table

I'm currently faced with a challenge involving an Angular Material table containing numerous columns. My goal is to selectively hide certain columns based on specific CSS media queries. This is the code snippet I have experimented with so far: HTML: ...

Leveraging oembed for dynamic content integration with SoundCloud in JSON

I'm looking to retrieve the latest 10 tracks of a user using oembed with json. $.getJSON("http://soundcloud.com/oembed", {url: "https://soundcloud.com/aviciiofficial", format: "json"}, function(data) { console.log(data.html); }) The d ...

Creating a dynamic dropdown menu: a step-by-step guide

<ul class="nav navbar-nav friend-label"> <li class="dropdown" ng-repeat="module in modules"> <a href="" class="dropdown-toggle" data-toggle="dropdown"> {{module.ModuleName}} < ...

Table does not have appropriate rowspan and colspan attributes

I've created a table using bootstrap, but it's not displaying as intended. I used row-span and col-span to format the table, and while most rows are correct, some are not appearing on the page. To better illustrate the issue, I have included an ...

Creating a unique Bootstrap background design

I have recently started using bootstrap and I am facing an issue. I want to change the background of a container when hovering over it, but I am having trouble getting it right. HTML <div class="container bg-black h-25 w-25 box"></div&g ...

Crafting an interactive form

Creating a form with 2 options (Yes/No) is my current task. When the user selects one of these options, I want a collapsible subform to appear with specific details related to that selection. If the user chooses the other option, a different collapsible su ...

Placing text and an image within a grid cell does not automatically stack them on top of each other

I have a large div with a grid display, consisting of 3 rows and 2 columns. I am attempting to include text directly below the photo within each cell. This is what my code looks like: <div class="arrange-fixes"> ...

Showcasing Portfolio Work in a User-Friendly Mobile Design

Currently revamping my portfolio website and looking for ways to optimize the display of my personal projects. I have a card-like interface in place that works well on desktop but only shows one project at a time on mobile devices. Seeking solutions to imp ...

Ways to decrease the width of a outlined material icon

Is there a way to adjust the appearance of this icon to make it appear thinner? I have tried using font-weight and stroke-width without success. .material-icons-outlined, .material-icons.material-icons--outlined { font-family: 'Material Icons Out ...

Retrieve MySQL data in HTML for transmission to a PHP script using jQuery

I am trying to extract the ID value in order to delete specific data from my MySQL database. This pertains to a project involving events, where I need to obtain the event ID upon clicking a button. This will allow me to update or delete the event based on ...

Managing multiple carousels simultaneously using the middle mouse button in Swiper.js

I am currently utilizing 5 carousels on my screen, all of which are operated by the same navigation buttons. In addition to this, I require the ability to control them using the middle mouse scroll. However, when I activate the mouse wheel control, only ...

Beginner attempting to comprehend Safari CSS font-size test outcomes

Currently, I am delving into the realm of CSS. To test my skills, I am making edits to an HTML file and previewing the outcome in Safari V11.0. My objective is to present an online version of a traditional printed report, complete with fixed columns and a ...

Having trouble with jQuery attribute selectors? Specifically, when trying to use dynamic attribute

This is the code I am working with $("a[href=$.jqURL.url()]").hide(); $.jqURL.url() fetches the current page URL. Unfortunately, this code is not functioning as expected. Is there a way to dynamically select elements? ...