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

169
Vistas
How to remove HTML clone element

What I am trying to create is basically a close button for a cloned form. The form along with the close button is generated onclick() using the following function:

$("#newVolton").click(function(){   
  var index = 0;
  $("#border").clone().attr('id', 'volton' + index).appendTo("#border");
  index++;
});

and I want to be able to close said form using the button that is generated alongside the specific instance of the form.

How should I got about deleting the instance?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I prefer to delegate

Make a main container and append to that Then each div has its own HTML and a delete button.

Note I hide the first delete to allow the clone source to stay

You can change it to a template if you do not want to have an initial div

$("#newVolton").on("click",function() {
  const $borders = $("#container").find(".border");
  const idx = $borders.length; // count the existing number of divs 
  $borders.eq(0).clone().attr('id', 'volton' + idx).appendTo("#container");
});
$("#container").on("click",".remove",function() { this.closest("div").remove() });
#container>div.border span.remove {
  display: none
}

#container>div.border~div.border span.remove {
  display: inline-block
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" id="newVolton">Add</button>
<div id="container">
  <div class="border" id="volton0">
    Some html <span class="remove">X</span>
  </div>
</div>

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