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
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 answers
Answer question

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 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!