Different classes on cells inside table

I have made a function which should make every 1st and 3rd table cell have their own class.
The table only consists of 3 cell in every row.

My function dosn´t work a 100%
Does anybody have any suggetions?
It´s like the 1st column dosnt get its class except for the 1st column in the first row.


function employee() {

var table = document.getElementById('employees'); 
var cells = table.getElementsByTagName('td'); 
var count = cells.length;
var c = 0;

for (var i = 0; i < count; i++) { 

c++;

if(c == 1) { cells[i].className = 'left-col';  } // 1 st column
if(c == 2) { cells[i].width = '9px;' } // 2 nd column
if(c == 3) { cells[i].className = 'right-col'; }  // 3 rd column
if(c == 4) {  c = 1; } 

}
}

onload = employee;


if(c == 4) { c = 0; }

Otherwise it will only ever be 1 the first time through since you always add one before testing its value.

Thank you for your answer (-:

Actually the solution for me was.


function employee() {

var table = document.getElementById('employees'); 
var cells = table.getElementsByTagName('td'); 
var count = cells.length;
var c = 0;

for (var i = 0; i < count; i++) { 

c++;

if(c == 4) {  c = 1; } 
if(c == 1) { cells[i].className = 'left-col';  } // 1 st column
if(c == 2) { cells[i].width = '9px;' } // 2 nd column
if(c == 3) { cells[i].className = 'right-col'; }  // 3 rd column

}
}

onload = employee;


But you guided me in the right direction felgall
Thanks again