jb60606 Posted July 29, 2007 Share Posted July 29, 2007 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 about 4 hrs ago, 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. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/62291-solved-alternate-row-color-with-domjavascript-shouldnt-this-work/ Share on other sites More sharing options...
jb60606 Posted July 29, 2007 Author Share Posted July 29, 2007 I think I should mention that when I similarily add a class name to a table cell, like below, it works fine. It seems as though it doesn't recognize what I want to do with "oRow.className =", but understands tdSymbol.className = "ajaxStockWatchlist-stockSymbol"; just fine. var oRow = this.table.insertRow(i); oRow.className = "altcolor"; //Add a cell for the stock's symbol var tdSymbol = oRow.insertCell(0); tdSymbol.className = "ajaxWatchlist-stockSymbol"; Link to comment https://forums.phpfreaks.com/topic/62291-solved-alternate-row-color-with-domjavascript-shouldnt-this-work/#findComment-309993 Share on other sites More sharing options...
mainewoods Posted July 30, 2007 Share Posted July 30, 2007 . light { background:#000000; } .dark { background-color:#FFFFFF; } use 'background-color' in the first one if that is not it, then do you have a class attached to the td's in the inserted row, that would overrule any class attached to the tr's Link to comment https://forums.phpfreaks.com/topic/62291-solved-alternate-row-color-with-domjavascript-shouldnt-this-work/#findComment-310521 Share on other sites More sharing options...
jb60606 Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks, I removed the TD classes (though they only changed the color and fixed the CSS, though it still doesn't work. There must be something else in the code that is denying this Link to comment https://forums.phpfreaks.com/topic/62291-solved-alternate-row-color-with-domjavascript-shouldnt-this-work/#findComment-310557 Share on other sites More sharing options...
jb60606 Posted July 30, 2007 Author Share Posted July 30, 2007 Problem solved. I deleted the CSS file and started from scratch. It doesn't have a problem with the TD classes, but something else was definately conflicting with the row highlighting. Thanks Link to comment https://forums.phpfreaks.com/topic/62291-solved-alternate-row-color-with-domjavascript-shouldnt-this-work/#findComment-310632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.