Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
Jquery coloring table cells according to condition and values

Trying to colour table rows that contain years<= 2004 in the second column and the third column should have value "Ne". What I am getting now is colored rows that contain only values in the third column "Ne" and condition years<=2005 is ignored. Is there some way to write condition using &&, or my syntax is bad?

$(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');
                  
                }

                
              }
              
            )
            
            }
          })
        })

});

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When you find applicable cell with text Ne, it needs to be in the same row as the matching cell with the year. The code with problem is finding all cells with Ne instead.

I would process row by row as below:

$("#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>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda