Web Hosting Talk







View Full Version : Javascript Looping


BigBison
04-15-2005, 02:14 AM
I have these tags, and I need to loop through them:

<li id="nav1">
<li id="nav2">
<li id="nav3">

Is this the correct code? I'm not certain about the "nav[i+1]" bit.

for (i=0; i<3; i++) {
x = document.getElementById("nav[i+1]");
this.className+=" over";
}

nnormal
04-15-2005, 10:39 AM
for (i=1; i<4; i++) {
x = document.getElementById("nav"+i);...

BigBison
04-15-2005, 04:48 PM
Thanks, nnormal. But i has to start at 0, for elsewhere in the function. I'll try ("nav"+(i++));

BigBison
04-15-2005, 06:31 PM
Or, I could just rename my ID's nav0-nav2.

:homer: D'oh!