467,910 Members | 1,606 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,910 developers. It's quick & easy.

Need Help Trying to merge 2 Function and CSS to work

I am trying to merge to scripting samples I for on a source code web
site and having limited luck. Then first one is called Zebra Tables
witch colors alternate rows of a table to look beter. The second is a
rule code that highlights the row you are currently moused over. Both
are making use of CSS style sheet to do all of their formating.
My problem is that the rollover is changing the text color but not the
color of the row background as the example does in the original code
which is what I am looking for out of this. Anyone have any ideas???
Link to the Samples are here:
My Code I have cobbled together

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<style type="text/css">

#mytable {
border: 1px solid #666666;
cellspacing: 0;

#mytable thead th,tfoot td{
background-color: #003366;
font-family: "lucida grande", verdana, sans-serif;
font-weight: bold;
color: #ffffff;
font-size: 10pt;
padding: 3px 8px;

#mytable tbody tr td {
font-family: "lucida grande", verdana, sans-serif;
font-size: 8pt;
padding: 3px 8px;
border-left: 1px solid #D9D9D9;

#mytable tbody tr td.selected {
font-size: 8pt;
color: #660000;
font-weight: bold;
#mytable tbody tr.ruled{
font-size: 11pt;
color: "#ccc";
border:1px solid #000;
<script type="text/javascript">
// this function is needed to work around
// a bug in IE related to element attributes
function hasClass(obj) {
var result = false;
if (obj.getAttributeNode("class") != null) {
result = obj.getAttributeNode("class").value;
return result;

function stripe(id) {

// the flag we'll use to keep track of
// whether the current row is odd or even
var even = false;

// if arguments are provided to specify the colours
// of the even & odd rows, then use the them;
// otherwise use the following defaults:
var evenColor = arguments[1] ? arguments[1] : "#fff";
var oddColor = arguments[2] ? arguments[2] : "#eee";

// obtain a reference to the desired table
// if no such table exists, abort
var table = document.getElementById(id);
if (! table) { return; }

// by definition, tables can have more than one tbody
// element, so we'll have to get the list of child
// &lt;tbody&gt;s
var tbodies = table.getElementsByTagName("tbody");

// and iterate through them...
for (var h = 0; h < tbodies.length; h++) {

// find all the &lt;tr&gt; elements...
var trs = tbodies[h].getElementsByTagName("tr");

// ... and iterate through them
for (var i = 0; i < trs.length; i++) {

// avoid rows that have a class attribute
// or backgroundColor style
if (! hasClass(trs[i]) &&
! trs[i].style.backgroundColor) {

// get all the cells in this row...
var tds = trs[i].getElementsByTagName("td");

// and iterate through them...
for (var j = 0; j < tds.length; j++) {

var mytd = tds[j];

// avoid cells that have a class attribute
// or backgroundColor style
//if (! hasClass(mytd) &&
// ! mytd.style.backgroundColor) {

mytd.style.backgroundColor =
even ? evenColor : oddColor;

// flip from odd to even, or vice-versa
even = ! even;
// -->

<script type="text/javascript">
written by Chris Heilmann for alistapart.
enables a rollover of rows for each table with the classname

function tableruler()
if (document.getElementById && document.createTextNode)
var tables=document.getElementsByTagName('table');
for (var i=0;i<tables.length;i++)
var trs=tables[i].getElementsByTagName('tr');
for(var j=0;j<trs.length;j++)
trs[j].onmouseover=function(){this.className='ruled';ret urn


<script type="text/javascript">

<meta NAME="GENERATOR" Content="SAPIEN Technologies, Inc. PrimalScript
<title>Test Page</title>
<body onload="stripe('mytable', '#fff', '#edf3fe');tableruler()"><a

<div id="bottle">

<h1>Test CSS and Java</h1>

<table class="ruler" id="mytable" >
<tr><th scope="col">test1</th><th scope="col">test2</th></tr>
<tr><td colspan="2">Summary</td></tr>


Jul 20 '05 #1
  • viewed: 1610

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by somaBoy MX | last post: by
2 posts views Thread by Aaron | last post: by
8 posts views Thread by Darryl Kerkeslager | last post: by
reply views Thread by Phil C. | last post: by
2 posts views Thread by davidw | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.