jQuery clone method

jQuery provides clone() method which  is used to create a copy of the matched elements.

<button id="cloneButton1">clone()</button>
<script type="text/javascript">
    $("#cloneButton1").click(function () {
	  $('.smallBox').clone().insertAfter(".smallBox");
    });
</script>
HTMl:
<div class="smallBox">
	I'm a small box
	<div class="smallInnerBox">I'm a small small inner box</div>
 </div>
For Live demo
Example 2 :
$(document).ready(function(){
  $('#btnClone').click(function(){
     $('#dvText').clone().appendTo('body');
     return false;
  });
});
HTML:
<div id="dvText">
   jQuery By Example Rocks!!!
</div>
<input type="button" id="btnClone" value="Clone Div" />
Share this nice post:

One thought on “jQuery clone method

Comments are closed.