Modify the color of the sidebar text in bootstrap from text-light to text-dark upon clicking with jQuery

Looking for assistance in integrating jQuery code to remove the "text-light" class when the side menu is open or when the navbar-toggler button is clicked.

$(document).ready(function() {
  $(".sidebarNavigation .navbar-collapse").hide().clone().appendTo("body").removeAttr("class").addClass("sideMenu").show();
  $("body").append("<div class='overlay'></div>");
  $(".navbar-toggle, .navbar-toggler").on("click", function() {
    $(".sideMenu").addClass($(".sidebarNavigation").attr("data-sidebarClass"));
    $(".sideMenu, .overlay").toggleClass("open");
    $(".overlay").on("click", function() {
      $(this).removeClass("open");
      $(".sideMenu").removeClass("open")
    })
  });
  $("body").on("click", ".sideMenu.open .nav-item", function() {
    if (!$(this).hasClass("dropdown")) {
      $(".sideMenu, .overlay").toggleClass("open")
    }
  });
  $(window).resize(function() {
    if ($(".navbar-toggler").is(":hidden")) {
      $(".sideMenu, .overlay").hide()
    } else {
      $(".sideMenu, .overlay").show()
    }
  })
})
<nav class="navbar navbar-expand-md bg-body navbar-dark sidebarNavigation" data-sidebarClass="navbar-dark bg-light ">
  <a class="navbar-brand" href="index.html"><img src="Media/David-Sanders-Logo-Transparent-White-Writing.png" width="210wh" class="img-fluid" alt="Responsive logo"></a>
  <!-- Toggler/collapsibe Button -->
  <button class="navbar-toggler" type="button" data-toggle="collapse">
  <span class="navbar-toggler-icon"></span>
  </button>
  <!-- Navbar links -->
  <div class="collapse navbar-collapse justify-content-center sidenav">

    <ul class="navbar-nav">
      <li class="nav-item"><a href="#" class="text-danger btn">Home</a></li>
      <li class="nav-item"><a href="#" class="text-light btn">Portfolio</a></li>
      <li class="nav-item"><a href="#" class="text-light btn">About</a></li>
      <li class="nav-item"><a href="#" class="text-light btn">Services</a></li>
      <li class="nav-item"><a href="#" class="text-light btn">Skills</a></li>
      <li class="nav-item"><a href="#" class="text-light btn">Contact</a></li>
    </ul>
  </div>

</nav>

Seeking help to incorporate this functionality into the existing jQuery code.

Answer №1

To start, I removed the text-light class from all list items.

<li class="nav-item"><a href="#" class="btn">Contact</a></li>

Next, I was able to reach the desired result by targeting the nav in css and overriding the bootstrap.

nav .navbar-nav li a{
  color: white;
}

The issue was resolved, although not in jQuery as originally intended. Either way, the same outcome was achieved.

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

Customize the background image in your Windows 8 app developed with HTML

While working on my app with the grid app template, I placed an image in the images folder. However, when I attempted to change the background image, it didn't seem to take effect. This is the code snippet that I used: HMTL <div id="contenthost" ...

Achieving checked checkboxes based on already selected values in AngularJS

function Test1Controller($scope) { var storeid = window.localStorage.getItem("storeid"); var serverData = ["Samsung Galaxy Note", "Samsung Galaxy S6", "Samsung Galaxy Avant","Samsung Galaxy Young"]; $scope.items= [] ; var selectedvalue="Samsu ...

Alternative solution to avoid conflicts with variable names in JavaScript, besides using an iframe

I am currently using the Classy library for object-oriented programming in JavaScript. In my code, I have implemented a class that handles canvas operations on a specific DIV element. However, due to some difficulties in certain parts of the code, I had t ...

Are there any SVG libraries available that can create line graphs similar to those seen in Google Analytics?

The line graph in Google Analytics that is created using SVG is quite impressive. Are there any libraries available that can generate similar line graphs to those in Google Analytics? ...

Is it possible to adjust the range of a range slider based on the selection of a radio button or other input method?

I have a query and I’m hopeful you can assist: function UpdateTemperature() { var selectedGrade = $( "input[name='radios']:checked" ).val(); $( ".c_f" ).text(selectedGrade); var value1 = $("#tempMin").val(); var value2 = $("#tempM ...

What is the best way to implement a callback function in JavaScript?

I am looking to update this code to incorporate a callback function. My goal is for the program to first call DynamicLoadScriptForEdit(), followed by calling ExecuteScriptForEdit. Unfortunately, my current implementation is not working as expected. window ...

Where can I find the CSS classes for Material-UI?

I am new to Material UI and I want to explore its grid examples. However, when I tried coding the example provided below, it gave me an error saying that there was no CSS file found to load for these examples. Without including the className parameter, I ...

Transferring information through AJAX and fetching through PHP

Below is my current AJAX code setup: optionScope.data().stage = 'b'; $.ajax({ url: "functions/contact.php", type: "post", data: {'stage': optionScope.data().stage}, success: function(data, status) { ...

Is it possible to target the HTML element or root node using the nth-child selector?

During one of my teaching sessions, I was discussing the nth-child() pseudo-selector with a student. I posed the question: Can you use the nth-child selector to target any HTML element? The response I received was negative, as it is not possible to select ...

Submitting PHP query to SQLite database using a button trigger

In my webpage, I am working with HTML and PHP to create a form. Within this form, there are two checkboxes: one populates its options from a table in the database related to products, while the other is a multi-select checkbox that gets populated from a di ...

Send information using jQuery AJAX

Currently, I am attempting to use AJAX to submit data to my table. Below is the form I have created for this purpose: <form> Total <input type="text" id="total" name="total" /><br /> Bill name<input type="text" id="bill-name" ...

What is the best way to ensure that two checkboxes are mandatory out of a total of three in

<input type="checkbox" name="Package1" value="packagename"> <input type="checkbox" name="Package2" value="packagename"> <input type="checkbox" name="Package3" value="packagename"> Is there a way to require the user to select at least t ...

Is there a way to display a message in a div container instead of using the alert box when there is a successful ajax response?

Hey there, I'm currently working on implementing error validation handling for a custom form that I've created. I'm looking to display the error messages in a designated div rather than using the standard browser alert box. Since I'm fa ...

Encountering the issue of receiving "undefined" along with other data while extracting information from JSON sources

My method for extracting values from JSON data using jQuery is as follows: $(document).ready(function() { $.ajax({ type : 'GET', url : 'outfitters.json', dataType : 'json ...

Find the sum of all characters in the values associated with each key in a JSON object

I'm attempting to calculate the total number of characters from the values of keys in a JSON object. Currently, I am only able to get the sum of the lengths of all the keys. Is there another method to achieve this? $.getJSON('lib/get-details.htm ...

How can data tables be generated using AJAX, JSON, HTML, and JS?

HTML: <table> <tr> <th>Student Name</th> <th>Student Grades</th> </tr> <tr> <td> <select name="dropdown" id= ...

The relative positioning is currently being obstructed

Having some trouble using position:relative to shift my logo to the left of my webpage. Oddly, moving it 20px seems to have no effect, but shifting it by 300px downwards causes it to vanish completely. Here's a snippet of my current code: .container ...

Question marks instead of font-awesome symbols

Currently, I am utilizing font-awesome (sass version - Link) on my asp.net website. The issue I am facing is that all fonts are showing up as ? I have thoroughly checked the font path and the CSS class, but everything appears to be correct Below is the ...

Activate Input by Clicking on Label in Internet Explorer version 8

I am trying to implement a widget in JQuery colorbox that allows users to load files. My approach involves using an input tag with type='file' and styling it with visibility:hidden. Additionally, I have created two labels that are styled like but ...

Tips on finding a JavaScript file using Google search

After releasing my jQuery plugin, I've noticed an increase in downloads. However, I'm curious to know where exactly it is being utilized. One idea I had was to search for the .js or .css file, potentially even looking at folder names. Is there a ...