How to algorithmically color the opposite diagonal of a table's diagonal
I have a table that I colored boxes that form the diagonal.
I am looking how to color algorithmically the opposite diagonal.
Demo : http://jsfiddle.net/pJt7x/
Javascript (1 == 2 must be replaced) :
for (i=0; i<=5; i++) {
$('table').append('<tr>');
for (j=0; j<=5; j++)
((i == j)||(1 == 2)) ?
$('tr:last').append('<td class="x"></td>') :
$('tr:last').append('<td></td>');
$('table').append('</tr>');
}
Answer : http://jsfiddle.net/pJt7开发者_开发百科x/2/
The opposite diagonal is i + j == 5
Do you need to fill both diagonals? this would work:
for (i=0; i<=5; i++) {
$('table').append('<tr>');
for (j=0; j<=5; j++)
((i == j) || (i+j == 5)) ?
$('tr:last').append('<td class="x"></td>') :
$('tr:last').append('<td></td>');
$('table').append('</tr>');
}
精彩评论