Can I do this with javascript/css?

Discussion in 'HTML' started by delerious@no.spam.com, Dec 2, 2003.

  1. Guest

    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.
    , Dec 2, 2003
    #1
    1. Advertising

  2. wrote:
    > 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;
    }
    Leif K-Brooks, Dec 2, 2003
    #2
    1. Advertising

  3. Guest

    On Tue, 02 Dec 2003 20:04:12 GMT, Leif K-Brooks <> wrote:

    > wrote:
    >> 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;
    >}
    >


    Thanks so much! That's a much better solution!
    , Dec 2, 2003
    #3
  4. Guest

    On Tue, 02 Dec 2003 20:04:12 GMT, Leif K-Brooks <> wrote:
    >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.
    , Dec 2, 2003
    #4
  5. wrote:
    > 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?
    Leif K-Brooks, Dec 2, 2003
    #5
  6. Nico Schuyt Guest

    Leif K-Brooks wrote:
    > wrote:


    >> 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?


    Maybe because he wants to show it to *more* than 1% of his visitors? :0
    Nico
    Nico Schuyt, Dec 2, 2003
    #6
  7. Richard Guest

    Leif! wrote:

    > wrote:
    >> 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;
    > }


    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.
    Richard, Dec 3, 2003
    #7
  8. rf Guest

    "Richard" <anonymous@127.000> wrote in message
    news:...
    > Leif! wrote:
    >
    > > wrote:
    > >> 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;
    > > }

    >
    > 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.
    rf, Dec 3, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    547
    Jonathan N. Little
    Mar 18, 2006
  2. mark4asp
    Replies:
    7
    Views:
    417
    mark4asp
    Oct 16, 2007
  3. Graham

    Can I register a CSS file - like javascript?

    Graham, Feb 10, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    98
    Graham
    Feb 10, 2004
  4. Julie Siebel
    Replies:
    4
    Views:
    136
    Dr John Stockton
    Feb 25, 2004
  5. Replies:
    7
    Views:
    195
Loading...

Share This Page