Solución del problema
Intente crear un bucle for para verificar si la tercera celda tiene clase o no.
/*----- Loop through each <tr> ------*/
$('tr').each(function(){
/*----- Check their all children whether any of them has 'passed class' ------*/
passedOnes = $(this).children('.passed');
if(passedOnes.length > 0){
/*----- Add class to parent ------*/
$(this).addClass('passedParent');
}
/*----- If nothing exists ------*/
else{
/*----- Add class to parent ------*/
$(this).addClass('failedParent');
}
});
Como la gente se enfada porque he usado jQuery, aquí hay otro enfoque escrito en Javascript... Cálmate muchacho. No quería dañar a nadie escribiendo en jQuery.:D
/*----- Get all <td> elements ------*/
var rows = document.getElementsByTagName("td");
/*----- Loop through them ------*/
for(var x = 0; x <= rows.length - 1; x++){
/*----- If element has passed class, then add class to its parent. ------*/
if(rows[x].classList.contains('passed')){
rows[x].parentElement.classList.add('passedParent');
}
/*----- If element has failed class, then add class to its parent. ------*/
else if(rows[x].classList.contains('failed')){
rows[x].parentElement.classList.add('failedParent');
}
}
No hay comentarios.:
Publicar un comentario