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 8443449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:08:30+00:00 2026-06-10T09:08:30+00:00

I have 2 lines of code in my JavaScript to dynamically change colors, one

  • 0

I have 2 lines of code in my JavaScript to dynamically change colors, one to change the background color of a table row and the other to change the font color:

rows[i].style.backgroundColor = 'red'
rows[i].style.color = 'white'

I need one more line of code to change the font color specifically when it is a hyperlink. I tried:

rows[i].style.link.color = 'white'

and several other variations but I can’t get the linked font colors to change. Can anyone help with this please? Thanks.

Full code:

var INTENDED_MONTH = 7 //August
// INTENDED_MONTH is zero-relative
now = new Date().getDate(),
rows = document.getElementById('scripture').rows;
if (new Date().getMonth() != INTENDED_MONTH) {
    // need a value here less than 1, or the box for the first of the month will be in Red
    now = 0.5
};
for (var i = 0, rl = rows.length; i < rl; i++) {
    var cells = rows[i].childNodes;
    for (j = 0, cl = cells.length; j < cl; j++) {
        if (cells[j].nodeName == 'TD'
  && cells[j].firstChild.nodeValue != ''
  && cells[j].firstChild.nodeValue == now) {
            rows[i].style.backgroundColor = 'red'
            rows[i].style.color = 'white'
            rows[i].style.a.color = 'white'
            $('html,body').delay(500).animate({ scrollTop: rows[i].offsetTop }, 2000);
        }
    }
}
  • 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-06-10T09:08:31+00:00Added an answer on June 10, 2026 at 9:08 am

    What about using CSS?

    tr{
       backgorund:red;
       color:white;
    }
    tr a{
       color:white;
    }
    

    If you need JavaScript, you can use

    var els=rows[i].getElementsByTagName('a');
    for(var i=0;i<els.length;i++){
       els[i].style.color = 'white';
    }
    

    Edit:

    You can also use

    tr a{
       color:inherit;
    }
    

    and then when you do

    rows[i].style.color = 'white'
    

    anchors’ color will be the same as row’s color – white -.

    Edit 2:

    As I said in my comment, even if you create the links with javascript, they are HTML elements so CSS affects them.

    But the problem is that the rule

    table.hovertable a:link, table.hovertable a:visited, table.hovertable a:hover, table.hovertable a:active {
        color: black;
    }
    

    overrides

    table.hovertable tr a {
        color: inherit;
    }
    

    Then, you need

    table.hovertable tr a:link {
        color: inherit;
    }
    

    which has the selector :link, so both rules have the same selectors and the last rule has effect.

    But I forgot to say that inherit doesn’t work on IE7 and before. Then, you could use

    rows[i].className+=' selected';
    

    and

    table.hovertable tr.selected{
       color:white;
       background:red;
    }
    
    table.hovertable tr.selected a:link{
       color:white
    }
    

    Edit3:

    If you want to set the same styles to the cell with current month, you can do

    var m=new Date().getMonth();
    document.getElementById('months').rows[Math.floor(m/6)].cells[m%6].className+=' selected';
    

    (suposing that the table has id="months")

    But then

    table.hovertable .selected{
       color:white;
       background:red;
    }
    
    table.hovertable .selected a:link{
       color:white
    }
    

    (.selected instead of tr.selected, now it’s a td).

    But I see that you still use color:inherit. Now that you set the styles using classes you don’t need it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have these lines of javascript code that I need to remove all
I have about 2000 lines of javascript code for my application. A lot of
I have a table of data which is generated dynamically with Javascript. Every few
I have some javascript code that loads images dynamically in a web page: imageSrc
I have the following line of code in javascript: (Math.random() + ) * 1000000000000000000
I have a JavaScript code which links to survey poll page. When I am
I have these lines of code in a command line project in VS2010 c++.
Basic question here - I have many lines of code that look something like:
i have this few lines of code FilterCondition CustomerID = new FilterCondition(Customer_ID,cust.Customer_ID,FilterCondition.FilterOperator.Equals); List<FilterCondition> conditions
I have the following lines of code: if(std::binary_search(face_verts.begin(), face_verts.end(), left_right_vert[0]) && std::binary_search(face_verts.begin(), face_verts.end(), left_right_vert[1]))

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.