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

193
Views
How to clone the div with button properties?

I would like to clone the entire div with the button properties. Is there any problem with my current code $("#dynamicsegment").clone().appendTo("#copieddiv")?

 <div id="dynamicsegment">
      <button type="button" id="start">Star</button>
      <button type="button" id="stop">Stop</button>
 </div>

    <script>
      $('#start').click(function(){
          $( "#stopdiv" ).hide();
          $( "#startdiv" ).show();
       }); 
    $('#stop').click(function(){
          $( "#stopdiv" ).show();
          $( "#startdiv" ).hide();
       });
 
    </script>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

The clone function copies all the properties (such as id, class, custom attribute) of the destination object. But its event handlers are not copied.

https://api.jquery.com/clone/

about 4 years ago · Juan Pablo Isaza Report

0

Here it is the code but I do not suggest to use id on cloned element because ID is unique.

$('#start').click(function(){
    $( "#stopdiv" ).hide();
    $( "#startdiv" ).show();
}); 
$('#stop').click(function(){
   $( "#stopdiv" ).show();
   $( "#startdiv" ).hide();
});

$('#button').on('click', function(){
  $(".cloned-element:last").clone().appendTo(".cloned-element:last");  
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="cloned-element" id="dynamicsegment">
     <button type="button" id="start">Star</button>
     <button type="button" id="stop">Stop</button>
</div>

<button id="button">Dublicate</button>

about 4 years ago · Juan Pablo Isaza Report

0

$('#start').click(function(){
  $("#dynamicsegment").clone().appendTo('body');
  $( "#stopdiv" ).hide();
  $( "#startdiv" ).show();
}); 
$('#stop').click(function(){
  $( "#stopdiv" ).show();
  $( "#startdiv" ).hide();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div id="dynamicsegment">
                  <button type="button" id="start">Star</button>
                  <button type="button" id="stop">Stop</button>
    </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!