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

103
Visualizações
select a td by table class

I've searched online for the answer but

$(".classname tbody tr td") or $("table.classname tbody tr td") 

don't work, I have got a table with only a class and I need to operate on tds etc.

the only reason why it don't work is probably the name of the class which is :table name name-surname.

the html is like this

<div class="tab">
  <table class="table name name-surname">
     <tbody>
        <tr>
          <td>name</td>
          <td>surname</td>
        </tr>
     </tbody>
  </table>
</div>

is this the real problem or i'm missing something? there's a way to go around it? i can't add an id or change the name of the class

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

0

You could always write your selector as this .table.name.name-surname tbody tr td

$(".table.name.name-surname tbody tr td").each(function() {
  console.log($(this).html())
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<div class="tab">
  <table class="table name name-surname">
    <tbody>
      <td>name</td>
      <td>surname</td>
    </tbody>
  </table>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Inorder for $(".classname tbody tr td") or $("table.classname tbody tr td") to work, the tablw should have a class called classname

console.log($(".classname tbody tr td"));
console.log($("table.classname tbody tr td"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div class="tab">
  <table class="table name name-surname classname">
    <tbody>
      <td>name</td>
      <td>surname</td>
    </tbody>
  </table>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Just use one of your table class like $(".table") or if you want to use multiple class connect them by dot like this: $('.table.name.name-surname tbody tr td')

Here is working sample:

$(".table tbody tr td").each(function(itm,el) {
   console.log(el);
});

$('.table.name.name-surname tbody tr td').each(function(itm,el) {
   console.log(el);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="tab">
        <table class="table name name-surname">
            <tbody>
                <tr>
                    <td>name</td>
                    <td>surname</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