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

170
Views
Cree una matriz a partir de filas de tablas con datos de múltiples celdas

Estoy tratando de crear una matriz simple con jquery a partir de una tabla con solo filas, pero una fila puede contener varios elementos de tiempo.

Solo pude encontrar soluciones para tablas con valores td únicos y sin hijos ...

Esta es mi tabla:

 <div id="customhours"> <table> <tbody> <tr> <td>Tuesday</td> <td> <time>17:00 - 18:00</time> </td> </tr> <tr> <td>Friday</td> <td> <time>16:00 - 17:00</time> <time>17:00 - 18:00</time> </td> </tr> </tbody> </table> </div>

La matriz que estoy buscando es:

 [["Tuesday", "17:00 - 18:00"], ["Friday", ["16:00 - 17:00, 17:00 - 18:00"]]]

Cualquier ayuda sería apreciada.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para cada fila, busque el día en el primer <td> y todas las etiquetas <time> en el último <td> :

 let a = [] // Results will go here $('#customhours tr').each(function() { let day = $(this).find('td:first-child').text() // eg Tuesday let times = [] $(this).find('td:last-child time').each(function(){ times.push($(this).text()) }) a.push([day, ( ( times.length == 1) ? times[0] : times )]) }) console.log(a)
 <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script> <div id="customhours"> <table> <tbody> <tr> <td>Tuesday</td> <td> <time>17:00 - 18:00</time> </td> </tr> <tr> <td>Friday</td> <td> <time>16:00 - 17:00</time> <time>17:00 - 18:00</time> </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!