/    Sign up×
Community /Pin to ProfileBookmark

Alternating Row Color Script doesn’t work in IE

Hey guys,

I don’t know much about javascript, but I can at least read through basic scripts and see how they function and what is happening. This code is basically just used to set up alternating row colors in a table. Its needed because the information is being filled dynamically form a database. The code is pretty simple:

[code] <script type=”text/javascript”>
function makeAltRows() {
var myTable = document.getElementsByTagName(‘tbody’);
for (i=0; i<myTable.length;i++) {
var rows = myTable[i].getElementsByTagName(‘tr’);
for (f=0; f<rows.length;f++) {
if (!(f % 2)) {
} else {
myTable[i].rows[f].setAttribute(“style”, “background-color:#e5e5e5;”);
}

}
}
} // END makeAltRows()
makeAltRows();
</script>

[/code]

It works fine in FF, but does not appear in IE. Any ideas? Here is the page:

[url]http://industryweapon.com/i7:Web,IndustryWeapon,customers,findaReseller[/url]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mataichiJul 02.2009 — I'm not sure you have the correct syntax for setting the background color attribute.

Maybe try changing

myTable[i].rows[f].setAttribute("style", "background-color:#e5e5e5;");



to



myTable[i].rows[f].style.backgroundColor="#e5e5e5";



Also, its kind of strange to have an if clause doing nothing.

You may want to change



if (!(f &#37; 2)) {

} else {

myTable[i].rows[f].setAttribute("style", "background-color:#e5e5e5;");

}



to



if (f % 2) {

myTable[i].rows[f].style.backgroundColor="#e5e5e5";

}
Copy linkTweet thisAlerts:
@polygoneJul 02.2009 — Edit: Nevermind
×

Success!

Help @pricecd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...