Alter the tab's color upon clicking the button

I am working on a multi-step form and I wanted to enhance the user experience by adding a button at the bottom of the page for easy navigation instead of relying on tabs at the top.

Although the button functions as intended, there is an issue with the tab's background color not changing when the user clicks on the next button.

<div class="right-col">     
    <div class="profile-content"
                <ul id="profile-tabs" class="nav nav-tabs">
                    <li class="active">
                        <a href="#customer-tab" data-toggle="tab">Customer Info</a>
                    </li>
                    <li>
                        <a href="#lead-tab" data-toggle="tab">Lead Info</a>
                    </li>
                </ul>

    <div class="tab-content tab-content-bordered panel-padding">
        <div class="widget-article-comments tab-pane panel no-padding no-border fade in active" id="profile-tabs-board">
           <form class="form-horizontal" action="leads_add_php.php" method="post" name="form1">


                        <div class="form-group">
                            <label for="tag" class="col-sm-3 control-label">Tag</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="tag" name="tag" placeholder="Tag" onchange="document.getElementById('output_tag').innerHTML = this.value"/>
                            </div>
                        </div>

                        <button type="button" id="next" name="next" class="btn btn-primary">Primary</button>
 <script>

$("#next").click(function(){ 
$("#customer-tab").removeClass("active");
$("#leads-tab").addClass("active");
$("#leads-tab .theme-default .nav-tabs .a").css("background", "red");

});
</script>
        </div> 

BEFORE

AFTER

When inspecting the element, here's the CSS snippet:

  element.style {
  }
  .theme-default .nav-tabs>li.active>a, .theme-default .nav-tabs>li.active>a:focus, .theme-default .nav-tabs>li.active>a:hover {
  background: #1d89cf;
  border-bottom: 2px solid #1a7ab9;
  }

Answer №1

To change the color of a specific list item, you need to assign an id to the li tag and then apply the desired color.

$(document).ready(function(){
  $("#next").click(function(){ 
$("#licustomer-tab").removeClass("active");
$("#lileads-tab").addClass("active");
$("#profile-tabs .active a").css("background-color", "red");

});
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<style>
.theme-default .nav-tabs>li.active>a, .theme-default .nav-tabs>li.active>a:focus, .theme-default .nav-tabs>li.active>a:hover {
  background: #1d89cf;
  border-bottom: 2px solid #1a7ab9;
  }
</style>
<div class="right-col">     
    <div class="profile-content">
                <ul id="profile-tabs" class="nav nav-tabs">
                    <li class="active" id="licustomer-tab">
                        <a href="#customer-tab" data-toggle="tab">Customer Info</a>
                    </li>
                    <li id="lileads-tab">
                        <a href="#lead-tab" data-toggle="tab">Lead Info</a>
                    </li>
                </ul>

    <div class="tab-content tab-content-bordered panel-padding">
        <div class="widget-article-comments tab-pane panel no-padding no-border fade in active" id="profile-tabs-board">
           <form class="form-horizontal" action="leads_add_php.php" method="post" name="form1">


                        <div class="form-group">
                            <label for="tag" class="col-sm-3 control-label">Tag</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="tag" name="tag" placeholder="Tag" onchange="document.getElementById('output_tag').innerHTML = this.value"/>
                            </div>
                        </div>

                        <button type="button" id="next" name="next" class="btn btn-primary">Primary</button>
        </div>

Answer №2

give this script a shot

 var $tabs = $('.tabbable li');
    $('#nexttab').on('click', function() {
        $tabs.filter('.active').next('li').find('a[data-toggle="tab"]').tab('show');
        $("#test").css("background-color", "red");

    });
    $('#test1').on('click', function() {
     $("#test").css("background-color", "white");
    });



   <form class="form-horizontal" action='/products/add/' method='post'>
          <fieldset>
          <div class="tabbable">
            <ul class="nav nav-tabs" id="tab_bar">
              <li class="active"><a href="#tab1" id="test1" data-toggle="tab">Product</a></li>
              <li><a href="#tab2" id="test" data-toggle="tab">Offer</a></li>
            </ul>

            <div class="tab-content">
              <!-- TAB 1 -->
              <div class="tab-pane active" id="tab1">
                <div class="control-group">
                  <label class="control-label" for="id_title">Title</label>
                    <div class="controls">
                      <input type="text" name="title">
                    </div>
                </div>
                <div class="control-group">
                  <label class="control-label" for="id_manufacturer">Manufacturer</label>
                    <div class="controls">
                      <input type="text" name="manufacturer">
                      <span class="help-inline">          
                    </div>
                    <div class="btn-group">

        <button class="btn" id="nexttab" type="button">Next</button>
    </div>
                </div>  
               </div>

              <!-- TAB 2 -->
              <div class="tab-pane" id="tab2">
                <div class="control-group">
                  <label class="control-label" for="id_condition">Condition</label>
                    <div class="controls">
                      <input type="text" name="condition">
                    </div>
                </div>
                <div class="control-group">
                  <label class="control-label" for="id_condition_note">Condition Note</label>
                    <div class="controls">
                      <input type="text" name="condition_note">
                    </div>
                </div>
              </div>            
            </div>
        <hr class="border-line"> <!-- STYLED IN FORMS.CSS -->

          </fieldset>
        </form>

view the fiddle here

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

"Encountered an issue with submitting the nodejs form

edit 2 After attempting to implement the following code snippet in my nodejs application, I encountered an issue where the form data was not being successfully posted to the database: router.get('/dashboard/users/forms/competition-form/:id', en ...

Unlocking the key to retrieving request headers in the express.static method

Utilizing express.static middleware allows me to avoid manually listing each asset in the routes. All my routing is managed through index.html due to my use of Vue JS. However, a feature necessitates me to extract specific information from the request hea ...

Utilizing XPath in Selenium: Extracting text from elements based on their adjacent elements

I'm facing an issue where I am unable to retrieve the text value from one end. Here is a snippet for better understanding: <div class=""> <span class="address_city">Glenwood</span> <span class="address_state">GA</span> ...

Trouble locating the ID selector within a nested Backbone view

Within this code snippet, I am utilizing the element controller pattern to display a collection of products. The main view template is rendering properly, showing all elements and the div selector "#cart-wrapper". However, when the main view calls the nest ...

Toggle the display of input fields based on radio button selection in Angular 2

We want to dynamically display additional input fields based on the selected radio button. Radio <div class="form-group"> <label>What would you like to evaluate?</label> <div class="radio"> <label> ...

Generating a jQuery dialog using a JavaScript object

I am working with a javascript / jquery object that can render html. This includes a div containing a table, an edit button, and a jquery popup dialog. Typically, I have called the jquery dialog within $(document).ready(function(){}); However, I am curio ...

resembling the nth-child selection for even elements within a list wrapped in <ul> tags

I recently utilized ng-repeat to iterate over a ul element. Unfortunately, I've run into an issue where I can't simply use nth-child(even) to change the background color of every other ul element. Does anyone have any alternative solutions or s ...

Utilizing jQuery to extract information from a JSON string

Currently, I have a set of records stored in an Oracle table and I am retrieving them using the following PHP code: $json_OutputArray = array(); while ($result = oci_fetch_assoc($parse_submitted_list)) { $json_OutputArray[] = $result; } $jsonstring ...

HighCharts.js - Customizing Label Colors Dynamically

Can the label color change along with gauge color changes? You can view my js fiddle here to see the current setup and the desired requirement: http://jsfiddle.net/e76o9otk/735/ dataLabels: { format: '<div style="margin-top: -15.5px; ...

The functionality of cloning in jQuery may encounter an issue where the text field remains enabled if the user selects an option labeled "other

Currently, I am working on a jQuery clone with my existing code and everything is functioning well. In the first scenario, if the user selects other from the dropdown menu, the text field becomes enabled. In the second scenario, when the user clicks ...

What are the steps to utilize Angular-fullstack without any server components?

The way Angular-Fullstack scaffolds the project is really impressive. However, I already have data being served through a restful API, so server components are unnecessary for me. Is there a way I can utilize only the client part and eliminate the server c ...

Display a magnified version of a thumbnail image using jQuery

I am currently working on enhancing my JQuery code to display a larger version of the thumbnail image. Here is the code I have so far, which only shows the thumbnail in its original size: $(".gallerythumbnail").click(function() { $(".showimagelightdow ...

Utilizing Multer with Node.js to seamlessly handle photo uploads

Currently, I am trying to upload some photos to my server by referencing my friend's code. However, when I console log the "req" (console.log(req)), the output is different from what I expected. More specifically, when I try to access req.file, it ret ...

The code is throwing a SyntaxError because it encountered an unexpected character in the JSON file at position 650xx

I am encountering an issue when attempting to save a JSON-formatted file from within the Javascript app I am developing. The app is running on Node v6.11.0 with Express on my local machine, port 3000. Occasionally, I come across the following error: Synta ...

Retrieve the file name (as well as other properties) when clicking on an image in dropzone.js

Is there a way in dropzone.js to retrieve the file name of an uploaded image when it is clicked? Check out this resource for more information: ...

What is the best way to assign an ajax array to a ColdFusion variable?

I've encountered an issue while working on HTML code that involves filling in special machine labels. Users need to input the number of lines, text size, and the text for each line they want in the resulting table. Currently, I'm seeking advice ...

The console is showing an error message stating that the variable "i" is not

Currently, I am developing the dashboard for my discord.js bot. While working on it, I encountered an issue where a variable I created to select an array from my JSON file is being reported as undefined by the console. $(function() { $.getJSON( "./data/ ...

The copyright (©) symbol is unresponsive to rotation

Why can't I rotate the © character? Am I missing something? .copy { font-size: 12px; font-family: Arial; writing-mode: vertical-rl; text-orientation: mixed; transform: rotate(180deg); } <span class="copy">&copy; This is not ...

Using AngularJS to dynamically change the background color of table rows based on the values stored in a data structure

I am looking to implement dynamic color backgrounds for table rows based on the state of a specific data structure Below is my attempt: <tr data-ng-repeat="shipping in shippings" data-ng-init="shippingIndex = $index" data-ng-class=& ...

Ensure that the height of the bootstrap image is limited by the dimensions of another column while still preserving its

I need to develop a versatile element with bootstrap that can accommodate images of different aspect ratios. To achieve this, I must trim the right side of the picture like so. <div class="container"> <div class="row"> <div class="col-12" ...