• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

Applying a CSS Rule with JS


Hi,

there is a line of JavaScript, which applies a CSS Rule "on click" or "on Rollover" to a specific item on the page, e.g. to a TD or to a font.
As I can remember (it is very long time ago), it was something like "onClick= this.style ...", But I'm not sure.

Does somebody knows about it?
Best thanks, Gitti

0
Gitti
Asked:
Gitti
  • 2
1 Solution
 
justinbilligCommented:
like so?

<style>

      .clsOnMouseOver
      {
            color:red;
            cursor:hand;
      }
      .clsOnMouseClick
      {
            color:blue;
      }
</style>
<html>
      <body>
            <span onmouseover="this.className='clsOnMouseOver';" onclick="this.className='clsOnMouseClick';"> Me </span>
      </body>
</html>
0
 
GittiAuthor Commented:
Hi and thanks for the reply. Although it was the answer to my question, would you please kindly formulate this one to JavaScript?

<span onclick="this.backgroundcolor='#993333' AND this.font-color='#ffffff'">

I don't know why it doesn't work?
Many thanks.
0
 
justinbilligCommented:
this.style.backgroundColor

this.style.fontColor but font color might just be color
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now