Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4618582
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:17:16+00:00 2026-05-22T02:17:16+00:00

I have written a code to change the CSS (color font) of tr, but

  • 0

I have written a code to change the CSS (color font) of tr, but it’s not working. If I remove the condition and use $(this).css("color","white"); then it works perfectly. But when I do this in if condition it fails to change the text color. What am I doing wrong with this one? Thanks.

$('tr').click(function () {
        $(this).toggleClass('hilite');          
        //$(this).css("color","white");
        if($(this).css("color") == "black"){
            alert("In first if");
            $(this).css("color","white");
        }else{$(this).css("color","black");}
    });  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:17:17+00:00Added an answer on May 22, 2026 at 2:17 am

    I suspect if you look at the return value of $(this).css("color") (e.g., in a debugger), you’ll find that it’s not “black” but instead “rgb(0,0,0)” or similar. (You can see it here — I get “rgb(0, 0, 0)” in Chrome, probably many other browsers as well.) You’ll need to handle that, either by keeping track of the colors (or perhaps based on your “hilite” [sic] class) or by parsing the result.

    The best thing, of course, is to have your “hilite” class control the text and background color, so you don’t have to do it in your JavaScript at all. E.g., with this rule:

    tr.hilite, tr.hilite td, tr.hilite th {
      background-color: black; /* Or whatever your dark background color is */
      color: white;
    }
    

    Off-topic: Every time you call $(), there are multiple function calls and a memory allocation involved, so if you’re going to do that several times in a row, it’s best to grab the result and reuse it.

    $('tr').click(function () {
        var $this = $(this);               // Grab it once
        $this.toggleClass('hilite');       // Use it throughout
        //$this.css("color","white");
        if($this.css("color") == "black"){ // (You'll still need to fix this)
            alert("In first if");
            $this.css("color","white");
        }else{$this.css("color","black");}
    });  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written code in -(void)applicationWillEnterForeground:(UIApplication *)application , but my application is not detecting
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have written this code inside a servlet to delete certain records from three
I have written this code in JavaScript and works perfectly fine when I include
I have written some code for displaying a drop down list, but the code
I have written python code which involves the use of dictionaries. I now wish
I have written this code where I want to increase / decrease number of
I have written this code in C# for WP7 : public void btn_handler(object sender,
I have written code that automatically creates CSS sprites based on the IMG tags
I have written code that opens 16 figures at once. Currently, they all open

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.