Ways to alter text color when clicked using jquery/javascript?

I have a unique fiddle which I have recreated based on the image provided below.

https://i.sstatic.net/UuBk2.jpg

This particular fiddle functions in such a way that when the two square boxes are clicked, another box appears at the bottom.

The JQuery code snippet I've utilized to achieve this effect is:

$("#franchisehub").click(function() {
  if ($('.franchisehubtv').css('display') == "flex") {
    $('.franchisehubtv').css('display', 'none');

  } else {
    $('#franchisehub').css('background-color', 'green'); 
    $('#franchisehub p').css('color', 'white');  // Additional line
    $('#cloudbasedmobile').css('background-color', 'white');    
    $('#businessanalytics').css('background-color', 'white');   
    $('#techsupport').css('background-color', 'white'); 
    // more lines for color settings go here

    $('.franchisehubtv').css('display', 'flex'); 
    // more lines for display settings go here
  }

});

Issue at Hand:

My goal is to change the text color inside the two squares (specifically "Franchise Hub or Cloud Based & Mobile") to white when the green image is clicked as shown in the provided screenshot.

I attempted to implement the following line to accomplish this task, but it appears to not be working:

$('#franchisehub p').css('color', 'white');
// Added line

Answer №1

Hi there! I would appreciate it if you could take a look at the code on my CodePen. Essentially, the issue arises when both text colors are changed to white - in the selected (green image) box everything works fine, but in another box with a white background, the text disappears. To address this, I only altered the text color of the paragraph in the selected box with a green background. I made modifications to the following two click functions:

$("#franchisehub").click(function() {
  if ($('.franchisehubtv').css('display') == "flex") {
    $('.franchisehubtv').css('display', 'none');
  } else {
    $('#franchisehub').css('background-color', 'green'); 
    $('#franchisehub p').css('color', 'blue !important'); 
    $('#franchisehub').find('p').css({color: '#fff'});
    // Additional background color changes for various elements
    $('.franchisehubtv').css('display', 'flex'); 
    // Additional display modifications for multiple elements
  }
});

$("#cloudbasedmobile").click(function() {
  if ($('.cloudbasedtextipad').css('display') == "flex") {
    $('.cloudbasedtextipad').css('display', 'none');
  } else {
    $('#franchisehub').css('background-color', 'white'); 
    $('#cloudbasedmobile').css('background-color', 'green');    
    // Additional background color changes for various elements
    $('#franchisehub').find('p').css({color: '#222'});
    $('#cloudbasedmobile').find('p').css({color: '#fff'});
    // Additional display modifications for multiple elements
  }
});

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

Challenge encountered in Rails with Ajax altering image

I have a Ruby on Rails application and I've integrated the acts_as_votable gem for handling likes and unlikes. Users can like or unlike a post. I've implemented AJAX functionality to update the like count without refreshing the page, and it&apo ...

Guide on adjusting the value for a Bootstrap slider

Using the bootstrap slider, I am trying to configure a way to assign a value to the handle from another variable. Although I came across a method that uses the data-slider-value attribute for this purpose, it did not work for me. <input id="gravite" na ...

Is it possible to create a column break within a CSS multicolumn design?

My text content sprawls over a CSS multicolumn layout with two, three, or four columns, utilizing CSS hyphenation. Sometimes, I want to terminate the text in one column early to allow the next paragraph to begin at the top of the next column. Is there a s ...

Which is better for handling events - jQuery delegation or function method?

Which approach is quicker and has broader browser support? 1. Utilizing a JavaScript function such as: function updateText(newtext) { $('div#id').text(newtext); } and incorporating it into an element's onclick event: <button onc ...

React's DangerouslySetInnerHTML() function is displaying content from the preceding page

Developing a website that displays user profiles. Encountering an issue where the profile description does not update correctly when switching from one profile to another. For instance: View user profile 1 User profile description shows User profile 1 d ...

troubles with dividing string

Recently delving into JavaScript/Angular development and encountering a little roadblock. I am attempting to break up a string of a textarea into an array at the \n character within a controller by utilizing $scope.mytext.split("\n"), however, I ...

Utilizing JavaScript to trigger an email with PHP variables included

i am trying to pass a few php variables using a javascript trigger. Everything seems to be working with the variables, databases, and script but I am struggling with the PHP part. Here is my attempt at the PHP code, although it clearly has some issues. I ...

Can you explain the functionality of the statement a:bc = 9 in JavaScript?

Currently in my JavaScript code, I have the equation a:bc = 9. Upon executing `console.log(bc)`, it correctly shows 9. However, if I try to `console.log(a)`, I receive an error stating that "a" is not defined. Can someone provide clarification on what i ...

The dropdown options are not loading with values

I am in the process of populating a dropdown menu with data retrieved from a database. Despite successfully fetching the data, I am encountering an issue where the dropdown menu is not being filled as expected. When I check the value using console.log, i ...

CSS: Element with overflowing content fails to display even with the overflow set to visible

I'm trying to enhance a fixed toolbar by adding a dropdown menu, but the .toolbar-dropdown-menu component isn't displaying correctly, as shown in this screenshot (tested on Google Chrome 80.0): https://i.stack.imgur.com/r5Cz0.png Initially, it ...

Exploring the power of Mongoose with GraphQL queries

Below is a mongoose Schema I have created: name : String, class : String, skills : [{ skill_name : String }] I want to convert this Schema into GraphQL inputs so that I can save them to MongoDB. Can someone help me with this? Something like: input Stud ...

Having trouble spinning the picture using Reel in Reactjs

I have recently started learning React and I am attempting to use jQuery reel to rotate a list of images by 360 degrees. While I have successfully implemented this using purely jQuery, I now want to migrate it over to Reactjs. The issue arises when trying ...

Designing rectangular divs with arrow elements

As I delve deeper into the world of CSS, my experiments have been yielding exciting results! From creating popup boxes to playing around with CSS styling, it's been a fun journey so far. However, I'm eager to challenge myself and expand my knowle ...

mobile-exclusive wordpress text area problem

There seems to be a padding issue that is only affecting mobile devices. https://i.stack.imgur.com/2Tbuc.png The cause of this problem has been somewhat identified, but the solution isn't clear without impacting the preview on computers. Here is th ...

The scrolling function of the jQuery UI select menu is not working properly on the Android browser

I am currently developing a mobile application that utilizes the jQuery UI select menu. The functionality works well, but I have encountered an issue with certain drop downs being too long to display properly. While my PC shows scrollable floating divs as ...

Enhancing the appearance of tables by formatting the columns

I'm currently working on designing a table to achieve the look shown in the image. I'm specifically looking to style the last 2 columns to achieve this effect. After searching extensively on Google and Stack Overflow, I couldn't find a solut ...

Fixed width in the left column with a fluid and clear:both in the right column in a 2-column layout

Struggling to figure this out after spending a lot of time on it. Here's what I'm trying to accomplish: I have a 2 column layout, with the left column having a fixed width of 220px and the right column having a fluid width. The code looks like ...

Ajax unable to update automatically

I'm currently in the process of setting up a registration box for new account creation. I'm attempting to load an HTML form through AJAX and pass data to a PHP file. My goal is to have the div containing the form reload every time the "register" ...

I would like some clarification on how bookmarking works

As I encountered a puzzling issue recently, I realize that I may need some assistance to navigate through it. It involves bookmarking some links for future reference. I attempted to search for answers online but found myself even more perplexed. Does boo ...

Experiencing strange reactionMessage

Here is a snippet of PHP code that I wrote for testing AJAX in a Cordova application. The PHP code looks like this: <?php if (isset($_POST["TEST"])){ if ($_POST["TEST"] == "TEST"){ $resp["GOOD"] = "TEST WORKS!!"; e ...