-1
$(function() {
var texto = $("#question_list tr:nth-child(1) td:nth-child(4)").text();
var result = (texto);
if (result=="Respondido"){
$("#answers").css("background","#FF0000");
}else if(result=="Arquivado"){
$("#answers").css("background","#00FF00");
}else if(result=="Em Análise"){
$("#answers").css("color","#0000FF");
}else if(result=="Aguardando Resposta"){
$("#answers").css("color","#0000FF");
}else{
$("#answers").css("color","#000000");
}
})
<table id="question_list">
<thead>
<tr>
<th>Título</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Teste Arquivo</td>
<td id="answers">Aguardando Resposta</td>
</tr>
<tr>
<td>Teste com upload de arquivo</td>
<td id="answers">Aguardando Resposta</td>
</tr>
<tr>
<td>Teste com upload de arquivo</td>
<td id="answers">Aguardando Resposta</td>
</tr>
<tr>
<td>Teste com Visualização de Arquivos</td>
<td id="answers">Aguardando Resposta</td>
</tr>
<tr>
<td>Teste para visualizar arquivo em anexo</td>
<td id="answers">Aguardando Resposta</td>
</tr>
</tbody>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
The texts in will undergo changes as it is in the JS code can be one of these values. The code however causes only the first row of the table to display the coloring of the text. How do I make the same happen to the other rows of the table?
Your lines only have 2 Tds each, so
td:nth-child(4)
finds nothing.– bfavaretto
Hello, actually it would have to be td:Nth-Child(2), but the result is the same, changes the text of the td in the first line and the others not, as it appears in the image. I suspect this should be inserted into a loop for, but do not know how to do it from the above code.
– Uadson Feitosa