Computing.Net > Forums > Web Development > Javascript/DOM change row color

Javascript/DOM change row color

Reply to Message Icon

Original Message
Name: jb60606
Date: July 29, 2007 at 13:46:36 Pacific
Subject: Javascript/DOM change row color
OS: Windows XP
CPU/Ram: 2.8Ghz/512MB
Model/Manufacturer: Homeade
Comment:

This little snippet of code is from a AJAX/PHP/JavaScript widget that retrieves stock quotes and fills in a table with the data.

-------------------------
From the JavaScript file:
-------------------------

for (var i = 0; i < oResult.stocks.length; i++) {
var altcolor = i % 2 == 0 ? 'light' : 'dark';
var oStock = oResult.stocks[i];

var oRow = this.table.insertRow(i);
oRow.className = "altcolor";


-------------------------
From the CSS file:
-------------------------

.light {
background:#000000;
}
.dark {
background-color:#FFFFFF;
}

I literally just started learning DOM and JavaScript yesterday, but shouldn't the above snippet work? It works in another plain JavaScript file that I have. I've also tried a few other similar methods I found on the web, though, they didn't see to work either.

Any help would be appreciated.
Thanks in advance.


Report Offensive Message For Removal


Response Number 1
Name: jb60606
Date: July 29, 2007 at 13:47:19 Pacific
Subject: Javascript/DOM change row color
Reply: (edit)

Also, if anyone know how to highlight the rows "onmouseover", that would be even better. Thanks again.


Report Offensive Follow Up For Removal

Response Number 2
Name: jb60606
Date: July 29, 2007 at 21:14:53 Pacific
Subject: Javascript/DOM change row color
Reply: (edit)

problem solved. I deleted the css file and started from scratch. Something in there had to be conflicting with the row color decloration.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Javascript/DOM change row color

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge