Intentar colorear las filas de la tabla que contienen años <= 2004 en la segunda columna y la tercera columna debe tener el valor "Ne" . Lo que obtengo ahora son filas coloreadas que contienen solo valores en la tercera columna "Ne" y se ignoran los años de condición <= 2005. ¿Hay alguna forma de escribir la condición usando && , o mi sintaxis es mala?
$(function(){ $("#randa").click(function(){ $("#lentele td:nth-child(2)").each(function() { if (parseInt($(this).text()) <=2005) { $("#lentele td:nth-child(3)").each(function() { if ($(this).text() == "Ne") { $(this).parent("tr").addClass('spalvinti'); } } ) } }) })});
Cuando encuentre una celda aplicable con el texto Ne , debe estar en la misma fila que la celda correspondiente con el año. El código con problema es encontrar todas las celdas con Ne en su lugar.
Procesaría fila por fila de la siguiente manera:
$("#randa").click(function(){ $("#lentele tr").each(function() { if (parseInt($(this).children('td:nth-child(2)').text()) <= 2005 && $(this).children('td:nth-child(3)').text() === 'Ne') { $(this).addClass('spalvinti'); } }); }); table { border: 1px solid #eee; } tr.spalvinti { background-color: green; } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="randa"> <table id="lentele"> <tbody> <tr> <td>1</td><td>2010</td><td>Taip</td> </tr> <tr> <td>2</td><td>1999</td><td>Ne</td> </tr> <tr> <td>3</td><td>2001</td><td>Ne</td> </tr> <tr> <td>4</td><td>2004</td><td>Ne</td> </tr> <tr> <td>5</td><td>2008</td><td>Ne</td> </tr> </tbody> </table> </div>