How to create clone of any object using jQuery

jQuery provides clone() method which creates deep copy set of all the elements which means it will copy the child nodes also. Clone() method is the best way to duplicate content of any element. For example, I have placed a div and a button. On click of button, we will clone the div and add it to body tag.

<div id="dvText">
   jQuery By Example Rocks!!!
</div>
<input type="button" id="btnClone" value="Clone Div" />

jQuery Clone() method code.

$(document).ready(function(){
  $('#btnClone').click(function(){
     $('#dvText').clone().appendTo('body');
     return false;
  });
});

As you see, I have just called the clone() method on the element which you want to clone and added it to body. Simple and Cool... 

See live Demo and Code

Feel free to contact me for any help related to jQuery. I will gladly help you.