Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

219
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda