Can I do this with javascript/css?

D

delerious

I have a page with a table. In a CSS file I have defined the TDs to have a
blue background color. The TDs also have a 'onMouseOver' function that
changes the background color to green, and a 'onMouseOut' function that
changes it back to blue. I currently have the 'onMouseOut' function just set
the background color to blue. I'm wondering if I can somehow have it refer to
the background color that is in the CSS file? That way if I change the color
in the CSS file, I won't have to change it in the javascript too.
 
L

Leif K-Brooks

I have a page with a table. In a CSS file I have defined the TDs to have a
blue background color. The TDs also have a 'onMouseOver' function that
changes the background color to green, and a 'onMouseOut' function that
changes it back to blue. I currently have the 'onMouseOut' function just set
the background color to blue. I'm wondering if I can somehow have it refer to
the background color that is in the CSS file? That way if I change the color
in the CSS file, I won't have to change it in the javascript too.

Don't use JS for that, use CSS instead:

td:hover {
background : green;
}
 
D

delerious

Don't use JS for that, use CSS instead:

td:hover {
background : green;
}

Wait, this appears to only work in Mozilla and Opera. Doesn't work in IE 5.5.
Maybe I have to use javascript after all.
 
L

Leif K-Brooks

Wait, this appears to only work in Mozilla and Opera. Doesn't work in IE 5.5.
Maybe I have to use javascript after all.

True. Is the effect really so critical that you have to bloat your page
to make it work everywhere? Why not just let IE users not see it?
 
N

Nico Schuyt

Leif said:
(e-mail address removed) wrote:
True. Is the effect really so critical that you have to bloat your
page to make it work everywhere? Why not just let IE users not see it?

Maybe because he wants to show it to *more* than 1% of his visitors? :0
Nico
 
R

Richard

Don't use JS for that, use CSS instead:
td:hover {
background : green;
}

Which applies to all table cells.
I have a one row, five column table. I want each cell to be a different
color.
Easily accomplished with mouseover but not in css.
Then if the browser doesn't accept the code, fine, they don't see the
effect.
 
R

rf

Richard said:
Which applies to all table cells.
I have a one row, five column table. I want each cell to be a different
color.
Easily accomplished with mouseover but not in css.
Then if the browser doesn't accept the code, fine, they don't see the
effect.

Once again you have demonstrated your chronic lack of understanding about
anything to do with CSS or even HTML.

td.one:hover{background: ...}
td.two:hover{background: ...}
td.three:hover{background: ...}
td.four:hover{background: ...}
td.five:hover{background: ...}
....
<td class="one">...
....
<td class="two">...

And so on.

Please read HTML specifications and the CSS specifications and make sure you
understand them before you post any more misguided bloody rubbish here.

Cheers
Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top