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

588
Views
jQuery: seleccionando cada td en un tr

Necesito una forma de interactuar con cada elemento td en un tr .

Para elaborar, me gustaría acceder a la primera fila de la tabla, luego a la primera columna, luego a la segunda columna, etc. Luego pasar a la segunda fila y repetir el proceso.

Algo como esto (pseudo-código):

 for each row in table { for each column in row { do cool things } }

jQuery:

 $('#tblNewAttendees tr').each(function() { alert('tr'); //Cool jquery magic that lets me iterate over all the td only in this row $(magicSelector).each(function(){ alert('hi'); }); });

HTML:

 <table> <thead> <th>someHeader</th> </thead> <tbody> <tr> <td>want to grab this first</td> <td> this second </td> </tr> <tr> <td>this third</td> <td>this fourth</td> </tr> </tbody> </table>
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Simplemente puede hacer lo siguiente dentro de su bucle TR:

 $(this).find('td').each (function() { // do your cool stuff });
over 4 years ago · Santiago Trujillo Report

0

No necesita un selector jQuery en absoluto. Ya tiene una referencia a las celdas en cada fila a través de la propiedad de cells .

 $('#tblNewAttendees tr').each(function() { $.each(this.cells, function(){ alert('hi'); }); });

Es mucho más eficiente utilizar una colección que ya tiene que crear una nueva colección a través de la selección de DOM.

Aquí he usado el jQuery.each() (docs) , que es solo un método genérico para la iteración y la enumeración.

over 4 years ago · Santiago Trujillo Report

0

Su $(magicSelector) podría ser $('td', this) . Esto tomará todos los td que son hijos de this , que en su caso es cada tr . Esto es lo mismo que hacer $(this).find('td') .

 $('td', this).each(function() { // Logic });
over 4 years ago · Santiago Trujillo 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!