Add x and y and get the module.
// ... var table$ = $('<table>'); for(var y = 0; y < s ; y++) { var tr$ = $('<tr>'); for(var x = 0; x < o; x++) { var td$ = $('<td>').css({ width: p_w, height: p_h, 'background-color': getColor(x, y) }); tr$.append(td$); } table$.append(tr$); } // ... var Color = { GRAY: '#aaa', WHITE: '#fff' }; function getColor(x, y) { return (x + y) % 2 === 0 ? Color.WHITE: Color.GRAY; }
Demo
source share