SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: changing td background color
-
Nov 17, 2002, 23:58 #1
- Join Date
- Jul 2002
- Location
- Fort Lauderdale
- Posts
- 123
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
changing td background color
I am using a script that changes id.style.background on a td.
http://www.unpossible.cc
It works the way it should in mac and pc ie. In ns however, the color does not change back the first time you mouse out. Does anyone know how to remedy this?
TIA
-
Nov 19, 2002, 00:19 #2
- Join Date
- Jun 2000
- Location
- Sydney, Australia
- Posts
- 3,798
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I would suggest posting the script if it's not too long.
-
Nov 19, 2002, 13:11 #3
- Join Date
- Jul 2002
- Location
- Fort Lauderdale
- Posts
- 123
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here is the javascript. get_obj() returns a reference to the object depending on which browser. The main concern would be with highlight() and unhighlight()
PHP Code:function get_obj(obj, is_style) {
if (is_style) {
if (document.getElementById) {
return document.getElementById(obj).style;
} else if (document.all) {
return document.all[obj].style;
} else if (document.layers) {
return document.layers[obj];
}
} else {
if (document.getElementById) {
return document.getElementById(obj);
} else if (document.all) {
return document.all[obj];
} else if (document.layers) {
return document.layers[obj];
}
}
}
function highlight(obj) {
get_obj(obj, 1).background = "#6D7887";
}
function unhighlight(obj) {
get_obj(obj, 1).background = "#4d555f";
}
PHP Code:a onMouseOver="highlight('TD_ID');" onMouseOut="unhighlight('TD_ID');"
-
Nov 19, 2002, 20:03 #4
- Join Date
- Jun 2000
- Location
- Sydney, Australia
- Posts
- 3,798
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here is my go. Seems to work OK in Mozilla and IE on both PC and Mac.
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <script language="javascript"> function changeElementColor(obj, color) { obj.style.backgroundColor = color; } </script> </HEAD> <BODY> <table> <tr> <td onmouseover="changeElementColor(this, 'blue')" onmouseout="changeElementColor(this, 'white')">foo</td> <td onmouseover="changeElementColor(this, 'blue')" onmouseout="changeElementColor(this, 'white')">bar</td> </tr> </table> </BODY> </HTML>
Bookmarks