Solved

onMouseover=(CSS Class)?

Posted on 2003-12-11
13
71,965 Views
Last Modified: 2013-11-19
any possibility of making a Mouseover within a <TD> tag styled by a CSS class?

i.e., <TD class="styleA" onMouseover="blah='styleB'" onMouseout="blah='styleA'">BLAH</TD>

Any help will be hugely appreciated... Thanks, TW
0
Comment
Question by:ChimpyLoLo
13 Comments
 

Author Comment

by:ChimpyLoLo
ID: 9922708
I know its a newbie question but no one's got an answer for me?
0
 
LVL 4

Expert Comment

by:Fendrin
ID: 9923929
yes it can be done, though not quite like that... as for why noone has answered you, this isn't a paid-tech support service... we 'experts' are people who donate our time and effort to helping others... so there isn;t always someone immediately around... that and we don;t get notified when a question comes in, so some time might go by...

here is what you do (if I am understanding your question correctly)

in your css, you do  the following:

a.linkstyle { /*link style goes here*/}
a.linkstyle:hover  { /*mouseover style goes here*/}
0
 
LVL 17

Accepted Solution

by:
dorward earned 50 total points
ID: 9923959
<td class="styleA" onmouseover="this.className='styleB';" onmouseout="this.className='styleA';">
0
 
LVL 1

Expert Comment

by:rightho
ID: 9923994
You can do something like this.  I got this code off the internet sometime ago.

<html>
<style type="text/css"> td.onmouse { background-color: #000000; color: #FFFFFF; } td.offmouse { background-color: #FFFFFF; color: #000000; } </style>
</style>
<body>
<table>
<td class="menuoff" onmouseover="className='onmouse';" onmouseout="className='offmouse';">Text that will be changed</td>
</table>
</body>
</html>

0
 
LVL 15

Expert Comment

by:Daydreams
ID: 9926573
Try this:

<html>
<head>
<title>Changing cell onmouseover</title>
<style>
<!--
td  {background-color:limegreen;cursor:default;border:1pt orange solid;}
  .green {background-color:green;color:yellow;}
  .limegreen {background-color:limegreen;color:teal;}
  .red {background-color:red;color:yellow;}
  .pink {background-color:pink;color:teal;}
-->
</style>
</head><body>
A colorful example of onmouseover effect, javascript and css: (hover mouse on cell)
<table style="border:1pt blue solid;background-color:lightblue;">
<tr><td class="limegreen"
onMouseover="this.className='green';"
 onMouseout="this.className='limegreen';">
 this is a cell
</td></tr><tr>
<td class="limegreen"
onMouseover="this.className='red';"
onMouseout="this.className='limegreen';">
 this is a cell
</td></tr>
</table>
</body>
</html>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:Daydreams
ID: 9926602
Just noticed my comment is an expansion on dorwards answer.. I just added more style for the example.
0
 
LVL 18

Expert Comment

by:bruno
ID: 9989382
dorward has provided you with the correct answer here, is there a reason you haven't closed out this question yet?
0
 
LVL 6

Expert Comment

by:ren_b
ID: 10026627
this works plenty well in mozilla and the likes:

<html>
<head>
<title>hover selector</title>
<style type="text/css">

box {
  padding: 3em;
  margin: 1em;
  border: 4px solid #000;
  background: #ff0;
  color: #060;
}

box:hover {
  border: 4px dashed #060;
  background: #000;
  color: #f0f;
}

</style>
</head>
<body>

<div id="box"> blah blah blah </div>

</body>
</html>
0
 
LVL 6

Expert Comment

by:ren_b
ID: 10026633
#box and #box:hover, oops
0
 
LVL 1

Expert Comment

by:IZING
ID: 10212158
yes it is possible, and very simple


create a file called root.js and put this code in it:

       function MouseEffect( event )
       {      switch( event.type )
             {      case "mouseover":
                        if( document.all )
                        {       window.event.srcElement.style.backgroundColor = '#840029';
      window.event.srcElement.style.color = '#ffffff';
                        }else{
                              event.currentTarget.style.backgroundColor = '#840029';
      event.currentTarget.style.color = '#ffffff';
                        }
                        break;
                  case "mouseout":
                        if( document.all )
                        {      window.event.srcElement.style.backgroundColor = '#948463';
      window.event.srcElement.style.color = '#ffffff';
                        }else{
                              event.currentTarget.style.BackgroundColor = '#948463';
      event.currentTarget.style.color = '#ffffff';
                        }            
                        break;
                  default:break;
            }
       }

basically this code work with both Netscape and IE.

Now in your html file, you should make a reference to the root.js file like this:
<script language="JavaScript" src="lib/root.js"></script>

then in your body, on the cell that you want to change the color you do this
<td align=center class=greyTd  onmouseover="MouseEffect(event);" onMouseOut="MouseEffect(event);" onClick="ChangePage('Aboutus.htm');">About me</td>


greyTd is just my css.


This will work for you. To see this page in effect check this link
http://www.jk2design.com/Gallery.htm

regards,

iz.
0
 

Expert Comment

by:momoaal
ID: 21049642
thanks  Daydreams  ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery scrollTop 2 41
How do i set sidebar width to 45% of screen width 1 29
P tag not forcing line space 2 23
CSS issue 8 11
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now