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

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

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 Denunciar

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 Denunciar

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