Solved

Changing Table Cell color at a Mouse Over event

Posted on 2004-04-05
9
28,439 Views
Last Modified: 2012-06-27
Hi,
  Does anyone know if it is possible to change color of an entire table cell on a Mouse over event. What I want to do is instead using a:hover for the link I want to use CSS to change color of the entire table cell of the link. I know I can do this using Images rollovers or javascript, but want to find out if there is anyway to do it in CSS.

Thanks
0
Comment
Question by:BrijBhasin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 100 total points
ID: 10758283
use javascript:
<html>
<head>
<script language="javascript".
<!--
function changeCellBG(el, myColor) {
      el.style.background =myColor;
}

//-->
</script>
</head>
<body>
<table cellspacing="1" border="1">
<tr style="background:red;">
<td width="200" height="20" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td>
</tr>
<tr style="background:orange;">
<td width="200" height="20" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td>
</tr>
<tr style="background:yellow;">
<td width="200" height="20" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td>
</tr>

</table>
</body>
</html>
0
 
LVL 9

Accepted Solution

by:
lombardp earned 150 total points
ID: 10758325
Similar to Yzlat, but CSS-based.

<html>
<head>
<style>
.classover {background-color: #ff0000;}
</style>
</head>

<body>
<table>
<tr>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
</tr>
<tr>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
</tr>
</table>

</body>
</html>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10758347
<style type="text/css">

.over { background-color:pink; }
.out  { background-color:red; }

</style>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 10758352
<html>
<head>
<title>untitled</title>
<style type="text/css">

.over { background-color:pink; }
.out  { background-color:red; }

</style>

</head>
<body>
<table cellspacing="1" border="1">
<tr style="background:red;">
<td width="200" height="20"  onmouseover="this.className='over'" onmouseout="this.className='out'"></td><td width="200" onmouseover="this.className='over'" onmouseout="this.className='out'"></td><td width="200" onmouseover="this.className='over'" onmouseout="this.className='out'"></td>
</tr>
<tr style="background:red;">
<td width="200" height="20" ></td><td width="200"></td><td width="200"></td>
</tr>
<tr style="background:red;">
<td width="200" height="20"></td><td width="200"></td><td width="200"></td>
</tr>

</table>
</body>
</html>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10758360
sorry  lombardp, my last solution is almost identical to yours. - I did not refresh the page
0
 
LVL 9

Expert Comment

by:lombardp
ID: 10758499
:)
0
 

Author Comment

by:BrijBhasin
ID: 10761195
Hi,
  Your solutions worked great accept for when mouseout happens the mouse over color remains there instead of switching back to the original color. Any idea why this is happening?

0
 

Expert Comment

by:lakshmanatessar
ID: 11396605
hello.
this script works well but i want a slight imprvisation. when clikced on  a link that bg color has to change to some other color and has to stay like that. when clicked on another cell then the previously clicked cell's bg color returns to the normal one and the latest clicked one changes its color. in this process the other cells has to be in the same features that changing bg color when hovered and returning to normal color when mouse is not hovered.
can anyone help?

thanks.
Lakshman Pilaka.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 14916733
ping
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

738 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