1
I’m solving a college exercise, and I’m having trouble passing the exact color to a zebra table.
I did the function this way, but when the table is built, it is coming out in green and yellow:
function rowValue(list) {
for (var i = 0; i < list.length; i++) {
if (i % 2 == 0) {
list[i][5] = '#4F4F4F';
}
else {
list[i][5] = '#FFFFFF';
}
}
}
And mounting the table in this way:
function buildTable(list, id) {
var html = "<thead> " +
" <tr> " +
" <th scope='col'>Proprietário</th> " +
" <th scope='col'>Endereço</th> " +
" <th scope='col'>Valor</th>" +
" <th scope='col'>Aluguel</th>" +
" <th scope='col'>Taxa</th>" +
" </tr>" +
"</thead>" +
"<tbody>";
rowValue(list);
for (var i = 0; i < list.length; i++) {
html += "<tr bgcolor = " + list[i][5] + ";>" +
"<td>" + list[i][0] + "</td>" +
"<td>" + list[i][1] + "</td>" +
"<td>" + list[i][2] + "</td>" +
"<td>" + list[i][3] + "</td>" +
"<td>" + list[i][4] + "</td>" +
"</tr>";
}
html += "</tbody>";
document.getElementById(id).innerHTML = html;
}
Welcome to Stackoverflow Ravel. Friend, what’s your question? Try to be clearer and more objective. Thanks!
– Filipe L. Constante
Thank Felipe, thank you! I am with the problem in which the colors of the table come out in green and yellow, not in gray in white as I determined in the creation of the function, I looked in several sites to see if I was wrong in hexadecimal.
– Ravel Sbrissa Okada
Why reinvent the wheel ? You can give this style "zebrado" by css using the pseudo selector
:nth-child(odd)
or:nth-child(even)
– Isac
@Isac, we are doing exercises to train the use of functions and have more familiarity with the language! Thanks for the tip!
– Ravel Sbrissa Okada