Steps for switching between two different colors in a tab menu

I am currently in the process of developing a tab menu using an unordered list <ul>. The menu consists of 7 tabs, with the first tab being active by default and displayed in a specific color while the remaining 6 tabs are inactive and should be styled differently. To achieve this functionality, I have implemented a jQuery script that toggles the "active" class when a tab is clicked.

$(document).ready(function(){
    $("ul#tabs li").click(function(e){
        if (!$(this).hasClass("active")) {
            var tabNum = $(this).index();
            var nthChild = tabNum+1;
            $("ul#tabs li.active").removeClass("active");
            $(this).addClass("active");
            $("ul#tab li.active").removeClass("active");
            $("ul#tab li:nth-child("+nthChild+")").addClass("active");
        }
    });
});

Below is my HTML code:

<html>
<head>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/modernizr.js"></script>
<script src="js/tabs.js"></script>
<style>

/* CSS styling for the tab menu */
#tab-menu ul li 
{
    /* Define styles here */
}

#tab-content
{
    /* Define styles here */
}

/* Styling for active tab */
.active
{
   /* Active tab styles go here */
}
</style>
</head>
<body>
<div id="tab-menu" class="tab-menu"><ul id="tabs">
    <li class="active"><a href="#"><img src="01.png" height="70" width="50"/></a></li>
    <li><a href="#"><img src="02.png" height="70" width="50"/></a></li>
    <li><a href="#"><img src="04.png" height="70" width="50"/></a></li>
    <li><a href="#"><img src="06.png" height="70" width="50"/></a></li>
    <li><a href="#"><img src="07.png" height="70" width="50"/></a></li>
    <li><a href="#"><img src="08.png" height="70" width="50"/></a></li>
    <li><a href="#"><img src="09.png" height="70" width="50"/></a></li>
</ul></div>
<div id="tab-content"></div>
</body>
</html>

While the click action to switch between tabs works correctly, I am looking for assistance in implementing the visual representation of inactive tabs in a different color. Can someone provide guidance on how to achieve this?

Answer №1

Check out this JSFiddle example

To fix the issue, just update your CSS by replacing .active with #tab-menu ul li.active

This simple change should solve the problem.

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

What is the best way to display the full image within the container?

The dimensions of the image are 6024x4024. I have tried hiding the overflow, but for some reason, I am unable to display the entire image within the container. Instead, it appears that the image is being zoomed in on. .section1{ background-image: ur ...

"Surprising quirks in the functionality of Bootstrap's image gallery

My goal is to create a matrix layout of 30 group member photos using HTML, CSS, and Bootstrap. Unfortunately, some of the photos are not aligning properly and are appearing in the wrong block, leaving some blocks empty. All the photos have the same aspect ...

After a single click, the functionality of jquery.nav.js seems to be malfunctioning

Encountering an error message: Uncaught TypeError: Cannot read property 'top' of undefined(…) jquery.nav.js:183 In an effort to convert my web app into a Single Page Application (SPA) using the jquery.nav.js library (available at https://githu ...

Retrieve the class name of the button or just its name

There is a button with the following HTML code: <input type='button' value='Generate' class="b1" name="b1" onclick='f1(this)' /> I am trying to retrieve the class name/ name attribute 'b1' when the button is ...

Error encountered with Google Places API due to Cross-Origin Resource Sharing

I have encountered an issue with my function that involves using AJAX to call the Google Places API. Despite the fact that the API supports CORS for both client and server, I am still receiving a CORS error. Unfortunately, JSONP is not a viable solution in ...

Clearing HTML Text Input Box When User Presses Enter

Currently, I am working on a lengthy program that is functioning almost flawlessly. However, there is one persistent issue: whenever I hit the Enter key while the text box is clicked, it clears the box and appends the data to the URL as if it were a GET re ...

Issue with change event not firing upon page load

In my production record creation page, I have implemented functionality to handle different line, shift, and date combinations. There are drop down menus for selecting the line and shift, as well as a jQuery date picker for selecting the date. One issue I ...

Creating a moving marquee effect in Ionic

I am attempting to achieve a marquee effect in Ionic, where the text automatically scrolls across the screen. It functions smoothly on the web simulator but appears incredibly choppy and not smooth when loaded onto an iPhone. I am wondering if there is a s ...

Select the picture to update the content of the text box

Seeking advice and guidance on a project. I have a variety of color icons and I want to set it up so that when someone clicks on a color icon, the name of the color is inserted into a hidden text field. The code for my hidden text field is as follows: &l ...

Tips for avoiding a noticeable sliding drawer when changing the direction of an HTML element

I am encountering an issue with the Daisy UI drawer component on my page. When I attempt to change the page direction using a JavaScript function, the drawer animates visibly from left to right or right to left, which is not the desired behavior. I have tr ...

CSS - Implementing Multi-Line Text Wrapping

Can anyone provide some guidance on how to handle an issue where having too much text in the description of an image pushes the image up? Thank you. I have created a basic fiddle - resize the window to see them inline. JSFiddle div.gallery { border: ...

Having trouble with setting an image as a background in CSS for Nativescript on iOS?

In my NativeScript app, I am trying to set an image as the background using the CSS property background-image: url("res://ic_more"). It works perfectly on Android, but unfortunately, it does not display on iOS devices. I have confirmed that the image is l ...

What is the best way to implement Bootstrap in Coda2?

I am new to web design and I am trying to incorporate Bootstrap into my HTML code using Coda2. Since I don't have access to a server, I am referencing the directory address of CSS files on my hard drive instead of a web address. Currently, the beginni ...

Setting a JavaScript value for a property in an MVC model

I am currently working on an asp.net mvc application and I am in the process of implementing image uploading functionality. Below is the code for the image upload function: $(document).ready(function () { TableDatatablesEditable.init(); ...

Tips for resetting a form after a successful AJAX submission

I've followed all the advice I could find, but I'm still struggling to reset the form after submission. Everything else is functioning correctly, except for this one aspect. My goal is simply to have the form reset once it has been submitted succ ...

using javascript to target a specific css selector attribute

I have a CSS file with the following code: .datagrid table tbody td { color: #00496B; border-left: 1px solid #E1EEF4; font-size: 16px ;font-weight: normal; } Is there a way to use JavaScript to dynamically change the font size? The code below worked ...

Utilizing PHP for a server-side backup in case the CDN is inaccessible

Looking to simulate some server-side functionality: <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript"> if (typeof jQuery == 'undefined&apo ...

What is the best method for adding a background image to a jumbotron in my Django project?

I have been struggling with this issue for some time now. Currently, I am working on a Django project and I need to add an image as the background in the jumbotron section. home.html {% extends 'blog/base.html' %} {% load static %} {% bl ...

Error: An error was detected due to a missing closing parenthesis after an argument list while attempting to utilize

Attempting to condense a string using the LZMA-JS library available here. This is how my javascript code looks: var reader = new FileReader(); reader.addEventListener("load", function () { var big_code = reader.result; console.log(big_code.lengt ...

Aligning floating elements in the center

Presently, I am working with the following code... <!DOCTYPE html> <html> <head> <title>Test</title> <meta charset="UTF-8" /> <link href="verna.css" type="text/css" rel="stylesheet" /> </head> ...