Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing Table Cell color at a Mouse Over event

Posted on 2004-04-05
9
Medium Priority
?
28,468 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 400 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 600 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
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…
Suggested Courses

722 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