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);
}
}
}
What about using CSS?
If you need JavaScript, you can use
Edit:
You can also use
and then when you do
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
overrides
Then, you need
which has the selector
:link, so both rules have the same selectors and the last rule has effect.But I forgot to say that
inheritdoesn’t work on IE7 and before. Then, you could useand
Edit3:
If you want to set the same styles to the cell with current month, you can do
(suposing that the table has
id="months")But then
(
.selectedinstead oftr.selected, now it’s atd).But I see that you still use
color:inherit. Now that you set the styles using classes you don’t need it