Tips for dynamically altering the color of a font awesome thumb icon within a paragraph

Within an ASP.NET MVC partial view, I've defined 2 thumbs within a paragraph.

The CSS (fontawesome) will change the color to blue upon hovering.

I am seeking a way to dynamically change the color of the thumbs based on certain conditions. Specifically, if the User has previously clicked the Like or Dislike thumb, I want that selection indicated by the color green the next time around. This visual cue helps in showing that they have already liked or disliked it.

How can I achieve this dynamic color change for the thumbs displayed within the paragraph?

@model GbngWebClient.Models.LikeOrDislikeVM

<style>
    .fa {
       cursor: pointer;
       user-select: none;
    }

   .fa:hover {
       color: blue;
   }

  .my-size {
      font-size: 20px;
   }
</style>

<div class="row">
<p><span class="blogLike my-size fa fa-thumbs-up"></span><span class="my-size"> : 
@Model.LikeCount</span> <span class="my-size"> | </span><span class="blogDisLike my-size fa fa- 
thumbs-down"></span><span class="my-size"> : @Model.DisLikeCount</span></p>
</div>

@Scripts.Render("~/bundles/jquery")

<script type="text/javascript">
   $(document).ready(function () {
     SetLike('@Model.LikeDisabled');
     SetDisLike('@Model.DisLikeDisabled');

    function SetLike(disabledSwitch) {
        $(".blogLike").attr('disabled', disabledSwitch);

        if (disabledSwitch == false )
        {
            // Indicate previous 'like' with green color.

            // This statement does not work.
            $(".blogLike").color('green');
        }
    }

    function SetDisLike(disabledSwitch) {
        $(".blogDisLike").attr('disabled', disabledSwitch);

        if (disabledSwitch == false)
        {
            // Indicate previous 'dislike' with green color.

            // This line does not work.
            $(".blogDisLike").color('green');
        }
    }
});
</script>

Answer №1

$(".blogDisLike").css('color', 'green');

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

Importing fonts using CSS

Currently, I have 4 different fonts that I need to incorporate into a website, and their files are saved within my website folder. Baskerville.ttc BellGothicstd-Black.otf BellGothicstd-Bold.otf JennaSue.ttf I attempted to import the fonts using @Import, ...

What is the most optimal method to retrieve data from a different list in Firebase?

My database consists of various teams and player names: https://i.sstatic.net/y5j6M.jpg I would like to know the most effective way to loop through each team and retrieve the names of players associated with them. For example, in the HTML code: Team: Sup ...

Facing CORS issue when trying to use the app on a device without network activity, although it works fine on

Currently, I am in the process of developing an Ionic app. Interestingly, the app runs smoothly in the browser; however, when it comes to running it on the device, the HTTP requests fail to load. Upon inspecting the app using Safari remote debugging, no er ...

The error message thrown by google-map-react is: "Invalid element type: a string was expected

Whenever I try to use the marker tag in my component, it stops working and throws an error like this: https://i.sstatic.net/FK30L.png This is my code: import React, { Component } from 'react'; import GoogleMap, { Marker } from 'google-map ...

What is the process for attaching an on-click event listener by utilizing an argument that is passed to a function in JavaScript?

These are the functions I have created: function type(message) { document.getElementById("body").innerHTML="<div id=\"textbox\" class=\"textbox\"></div><div id=\"oc\&q ...

Using CSS Translate can cause discrepancies in the X and Y values retrieved from getBoundingClientRect

In my React project, I am working on animating the transition from multiple images to one when a specific image is selected. The CSS I am using for the animation is based on the x and y position of the original clicked image. Currently, these values are h ...

Import failures in Three.js could be attributed to potential issues with Webpack

Please note: I am utilizing create-react-app along with three.js v0.99.0. In my current project, I am faced with the challenge of importing specific modules from three.js to avoid bundling the entire library, which results in a large uncompressed file siz ...

How can I obtain the current state of HTML checkboxes from a local JSON file?

I have an HTML table with checkboxes, and I want to save the state of each checkbox in a local .JSON file instead of using localStorage. When the page reloads, I want it to automatically load the saved JSON file to retrieve the previously configured checkb ...

In the production build of Next.js, accessing dynamic routes may lead to a 404 error

Incorporating Dynamic Routing in my next JS project has been a seamless process so far. During development mode, all features are functioning as expected. However, I noticed that when I access a dynamic page for the first time, it loads without any issue ...

Express.js throws an error of type TypeError when attempting to set a property 'session' on an undefined object

Encountering this issue when attempting to start my express server with node server.js, and I'm struggling to identify the root cause. Despite updating my app with express 4.0, I can't seem to pinpoint the error. Can anyone assist in identifying ...

Django CSS graphical interface for selecting styles

I am looking to implement a feature that allows users to select an "interface theme": To enable users to change the theme across all templates, I have created a dropdown in my base.html. For all my HTML templates, I utilize a base.html file by extending ...

"Passing data from a child component to a parent component using Vue's emit

offspring template: ` <li v-for="option in listaOptiuni" :key="option.id"> <input @change="updateSelectAllToateOptiunile(); sendListaToateOptiunile()" v-model="listaToateOptiunile" :value="o ...

Troubleshooting issues with Vue.js page routing

Currently, I am diving into the world of vue.js and encountering difficulties with setting up routing. My goal is to utilize templates stored in separate HTML files, rather than inline templates. The issue I'm facing is that the routing does not seem ...

Shuffle the elements within each container in the DOM

Currently, I am focusing on designing a card-based layout where each card contains details about the product. One important detail is the phone number, which is displayed in the format 555-555-5555. My current goal is to clear the text value of the phone ...

Transitioning between modals using Tabler/Bootstrap components in a ReactJS environment

Currently, I am constructing a Tabler dashboard and incorporating some ReactJS components into it. Initially, I used traditional HTML pages along with Jinja2 templates. However, I have now started integrating ReactJS for certain components. I prefer not t ...

After the php array has been json_encoded, what should be my next step?

Exploring the realms of PHP and JavaScript is new to me, and I'm encountering difficulty in finding a way for them to communicate effectively. After converting a PHP array into JSON using json_encode(), I feel unsure about the next steps. Despite sear ...

Having an issue with Bootstrap icons displaying as blank boxes across all browsers

It seems to be a similar issue to what's discussed here: Glyphicons rendering as empty box Despite my efforts to search for solutions online, I can't figure out what the problem is. It all began when I first started using bootstrap. I've e ...

Tips for retrieving a link href with selenium

Here is a link from the webpage I am automating: https://i.sstatic.net/kfFEa.png Upon inspecting its element, I found this: https://i.sstatic.net/v501c.png I'm interested in extracting only /console/agent_invoices/2297294 which is in the href ...

What is the best way to select multiple items using mongoose?

For instance, consider this list: [ { name: "John" }, { name: "Mike" }, { name: "Homer" }, { name: "Bart" }, { name: "Dmitry" }, { name: "Dan" } ] If I want to select specific objects ...

What is the best way to assign a percentage width based on a variable in jQuery?

Is there a way to assign a dynamic width value to an element? Here is the code I am using: $(".menu_list_item").css({ width: width + "%" }); Unfortunately, this doesn't appear to be functioning correctly. If anyo ...