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

216
Views
Remove dynamically appended <TR> from jquery

I append the <tr> to <tbody>

for (var i = 0 ;i < 12 ;i++){
  $(`<tr><td>test</td></tr>`).appendTo('#songsTbody');
}

to this html.

<tbody id="songsTbody">
</tbody>

Now I want to remove() only appended <tr> but

$('#songsTbody').remove();

it remove <tbody> itself.

How can I remove only <tr>??

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

0

You can pass a selector into the .remove() call so if there are no other s and you want to remove them all, you could do $('#songsTbody').remove('tr') or even just $('#songsTbody tr').remove().

If you need to just remove the last one that was added, you could try $('#songsTbody tr:last-child').remove() or $('#songsTbody').remove('tr:last-child')

about 4 years ago · Juan Pablo Isaza Report

0

You can recognize appended <TR> adding a data attribute or a class.

for (var i = 0 ;i < 12 ;i++){
  $(`<tr class="appended"><td>test</td></tr>`).appendTo('#songsTbody');
}

and after you can easily remove just new TR with

$('#songsTbody').remove('tr.appended')
about 4 years ago · Juan Pablo Isaza Report

0

Save it in a variable(s).

var arr = []
for (var i = 0; i < 12; i++) {
  var elem = $(`<tr><td>test</td></tr>`);
  elem.appendTo('#songsTbody');
  arr.push(elem);
}

// remove:
arr.forEach((elem) => elem.remove());

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!