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

316
Views
Agregar un objeto tr clonado en un tbody, usando jQuery

Quiero clonar a los hijos de #secret_tr en el .table tbody

 <table class="table"> <thead> <tr> <th>Key</th> <th>Value</th> <th></th> </tr> </thead> <tbody> </tbody> </table> <div id="secret_tr" style="display:none;"> <div> <table> <tbody> <tr> <td>Foo</td> <td>Bar</td> <td> </td> </tr> </tbody> </table> </div> </div>

Esto no funciona aparentemente:

 var template = $("#secret_tr").children().clone(); var tr = template.find("table tbody tr"); $("table.table tbody").append(tr);

Sin embargo, si ejecuto esta línea en su lugar, los td s se agregan, excepto que ahora me falta el tr :

 $("table.table tbody").append(tr.children());
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esta costura para trabajar. Creo una referencia a la plantilla. Y con una referencia al <tr> creo un clon del elemento. Este clon se puede agregar <tbody> .

 var template = $("#secret_tr"); var tr = template.find("table tbody tr").clone(); $("table.table tbody").append(tr);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table class="table"> <thead> <tr> <th>Key</th> <th>Value</th> <th></th> </tr> </thead> <tbody> </tbody> </table> <div id="secret_tr" style="display:none;"> <div> <table> <tbody> <tr> <td>Foo</td> <td>Bar</td> <td> </td> </tr> </tbody> </table> </div> </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!