Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!