I create a table
dynamically from the result of a query in the database.
But I would like to have a control to eliminate the <tbody>
of it.
I can do this using the command:
var body = $("#tbSemana").find('tbody').remove();
$("#tbSemana").append(document.createElement('tbody'));
However, the table
does not have id , how can I make this same deletion without id ?
follows table created:
for (var i = 0; i < ciclos.length; i++) {
var atual = ciclos[i];
var html = "<table class=\"table\"><thead>" +
"<tr>" +
"<th>Pts Sem. 1</th>" +
"<th>Qualificação Sem. 1</th>" +
"<th>Pts Sem. 2</th>" +
"<th>Qualificação Sem. 2</th>" +
"<th>Pts Sem. 3</th>" +
"<th>Qualificação Sem. 3</th>" +
"<th>Pts Sem. 4</th>" +
"<th>Qualificação Sem. 4</th>" +
"</tr>" +
"</thead<tbody><tr>";
if (semana[0] != null) {
if (true) {
//html += "<td>" + atual.id + " - " + atual.nome + "</td>";
html += "<td style=\"text-align: center; \">" + atual.totPst1 + "</td>";
html += "<td style=\"text-align: center; \">" + atual.grad1 + "</td>";
a += ciclos[i].totPst1;
}
else {
//html += "<td>" + atual.id + " - " + atual.nome + "</td>";
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
}
else {
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
if (semana[1] != null) {
if (true) {
html += "<td style=\"text-align: center; \">" + atual.totPst2 + "</td>";
html += "<td style=\"text-align: center; \">" + atual.grad2 + "</td>";
b += ciclos[i].totPst2;
}
else {
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
}
else {
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
if (semana[2] != null) {
if (true) {
html += "<td style=\"text-align: center; \">" + atual.totPst3 + "</td>";
html += "<td style=\"text-align: center; \">" + atual.grad3 + "</td>";
c += ciclos[i].totPst3;
}
else {
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
}
else {
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
if (semana[3] != null) {
if (true) {
html += "<td style=\"text-align: center; \">" + atual.totPst4 + "</td>";
html += "<td style=\"text-align: center; \">" + atual.grad4 + "</td>";
d += ciclos[i].totPst4;
}
else {
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
}
else {
html += "<td style=\"text-align: center; \">0</td>";
html += "<td style=\"text-align: center; \">-</td>";
}
html += "</tr>";
//$("#tbgrad").find('tbody').append(html);
html += "</tbody></table>";
}